UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

72 lines (71 loc) • 4.08 kB
import path from "node:path"; import fs from "node:fs/promises"; import { appendRegularFile as appendRegularFile$1, appendRegularFileSync as appendRegularFileSync$1, assertAbsolutePathInput, canonicalPathFromExistingAncestor as canonicalPathFromExistingAncestor$1, ensureDirectoryWithinRoot, findExistingAncestor, findExistingAncestor as findExistingAncestor$1, movePathToTrash, pathExists as pathExists$1, pathExistsSync, readLocalFileFromRoots, readRegularFile as readRegularFile$1, readRegularFileSync as readRegularFileSync$1, resolveAbsolutePathForRead as resolveAbsolutePathForRead$1, resolveAbsolutePathForWrite, resolveLocalPathFromRootsSync, resolveRegularFileAppendFlags, sanitizeUntrustedFileName as sanitizeUntrustedFileName$1, statRegularFile, statRegularFileSync as statRegularFileSync$1, withTimeout as withTimeout$1 } from "@openclaw/fs-safe/advanced"; import { FsSafeError as FsSafeError$1 } from "@openclaw/fs-safe/errors"; import { isPathInside as isPathInside$1 } from "@openclaw/fs-safe/path"; import { writeExternalFileWithinRoot } from "@openclaw/fs-safe/output"; import { openLocalFileSafely as openLocalFileSafely$1, readLocalFileSafely, resolveOpenedFileRealPathForHandle, root } from "@openclaw/fs-safe/root"; import { readSecureFile } from "@openclaw/fs-safe/secure-file"; import { walkDirectory as walkDirectory$1, walkDirectorySync as walkDirectorySync$1 } from "@openclaw/fs-safe/walk"; //#region src/infra/fs-safe.ts const readLocalFileFromRoots$1 = readLocalFileFromRoots; async function root$1(e, t) { return await root(e, t); } async function ensureAbsoluteDirectory$1(e, t) { const n = path.resolve(e); const r = t?.scopeLabel ?? "directory"; const i = await findExistingAncestor(n); if (i && i !== n) { const e = await ensureDirectoryWithinRoot({ rootDir: i, requestedPath: path.relative(i, n), scopeLabel: r, mode: t?.mode }); return e.ok ? e : { ok: false, error: new Error(e.error) }; } if (i) try { const e = await fs.lstat(n); if (!e.isSymbolicLink() && e.isDirectory()) return { ok: true, path: n }; } catch {} return { ok: false, error: /* @__PURE__ */ new Error(`Invalid path: must stay within ${r}`) }; } async function writeExternalFileWithinRoot$1(e) { const t = path.resolve(e.rootDir, e.path); const n = await writeExternalFileWithinRoot({ rootDir: e.rootDir, path: e.path, write: e.write, staging: "sibling", producerIsolation: "private-directory", fallbackFileName: e.fallbackFileName ?? e.tempPrefix }); return { path: path.join(path.dirname(t), path.basename(n.path)) }; } /** @deprecated Use root(rootDir).read(relativePath, options). */ async function readFileWithinRoot(e) { return await (await root(e.rootDir)).read(e.relativePath, { hardlinks: e.rejectHardlinks === false ? "allow" : "reject", maxBytes: e.maxBytes, symlinks: e.allowSymlinkTargetWithinRoot === true ? "follow-within-root" : "reject" }); } /** @deprecated Use root(rootDir).write(relativePath, data, options). */ async function writeFileWithinRoot(e) { await (await root$1(e.rootDir)).write(e.relativePath, e.data, { encoding: e.encoding, mkdir: e.mkdir }); } //#endregion export { withTimeout$1 as A, resolveRegularFileAppendFlags as C, statRegularFileSync$1 as D, statRegularFile as E, writeFileWithinRoot as M, walkDirectory$1 as O, resolveOpenedFileRealPathForHandle as S, sanitizeUntrustedFileName$1 as T, readRegularFileSync$1 as _, canonicalPathFromExistingAncestor$1 as a, resolveAbsolutePathForWrite as b, isPathInside$1 as c, pathExists$1 as d, pathExistsSync as f, readRegularFile$1 as g, readLocalFileSafely as h, assertAbsolutePathInput as i, writeExternalFileWithinRoot$1 as j, walkDirectorySync$1 as k, movePathToTrash as l, readLocalFileFromRoots$1 as m, appendRegularFile$1 as n, ensureAbsoluteDirectory$1 as o, readFileWithinRoot as p, appendRegularFileSync$1 as r, findExistingAncestor$1 as s, FsSafeError$1 as t, openLocalFileSafely$1 as u, readSecureFile as v, root$1 as w, resolveLocalPathFromRootsSync as x, resolveAbsolutePathForRead$1 as y };