openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
67 lines (66 loc) • 2.08 kB
JavaScript
import { r as normalizeFsSafeNativeEnv } from "../fs-safe-env-CCe2lU-3.mjs";
import { readFileSync } from "node:fs";
import { serialize } from "node:v8";
import { parentPort } from "node:worker_threads";
import { copyTree, createCloneSource, probeTreeClone, readCloneFileMetadata } from "@openclaw/fs-safe/copy";
import { configureFsSafeNative, getFsSafeNativeConfig } from "@openclaw/fs-safe/config";
//#region src/infra/fs-safe-copy.worker.ts
function failure(error) {
return {
type: "failed",
message: error instanceof Error ? error.message : String(error),
...error instanceof Error && "code" in error && typeof error.code === "string" ? { code: error.code } : {}
};
}
normalizeFsSafeNativeEnv();
if (parentPort) {
const nativeConfig = getFsSafeNativeConfig();
const { serveWorkerTasks } = await import("../worker-task-server-DCO6XUS8.mjs");
configureFsSafeNative(nativeConfig);
serveWorkerTasks(async (input) => {
const command = input;
try {
switch (command.type) {
case "probe": return {
type: "probe",
backend: probeTreeClone(command.parent)
};
case "metadata": return {
type: "metadata",
entries: await readCloneFileMetadata(command.paths)
};
default: throw new Error("Unknown native worktree read operation");
}
} catch (error) {
return failure(error);
}
});
} else {
const controller = new AbortController();
const abort = () => controller.abort();
process.on("SIGTERM", abort);
let reply;
try {
const command = JSON.parse(readFileSync(0, "utf8"));
switch (command.type) {
case "create":
await createCloneSource(command.destination, { signal: controller.signal });
break;
case "copy":
await copyTree(command.source, command.destination, {
clone: "always",
signal: controller.signal
});
break;
default: throw new Error("Unknown native worktree operation");
}
reply = { type: "written" };
} catch (error) {
reply = failure(error);
} finally {
process.off("SIGTERM", abort);
}
process.stdout.write(serialize(reply));
}
//#endregion
export {};