mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 15:50:46 +00:00
Refactor file access to use fs-safe primitives (#78255)
* refactor: use fs-safe primitives across file access * fix: preserve invalid managed npm manifests * fix: keep fs seams for startup metadata
This commit is contained in:
committed by
GitHub
parent
0d73f174a9
commit
b85b1c68d1
@@ -1,4 +1,5 @@
|
||||
import { configureFsSafePython } from "@openclaw/fs-safe/config";
|
||||
export { root } from "@openclaw/fs-safe/root";
|
||||
export { isPathInside } from "@openclaw/fs-safe/path";
|
||||
export {
|
||||
readRegularFile,
|
||||
@@ -21,6 +22,7 @@ export function isFileMissingError(
|
||||
err &&
|
||||
typeof err === "object" &&
|
||||
"code" in err &&
|
||||
(err as Partial<NodeJS.ErrnoException>).code === "ENOENT",
|
||||
((err as Partial<NodeJS.ErrnoException>).code === "ENOENT" ||
|
||||
(err as { code?: unknown }).code === "not-found"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,13 @@ import {
|
||||
resolveMemorySearchConfig,
|
||||
type OpenClawConfig,
|
||||
} from "./config-utils.js";
|
||||
import { isFileMissingError, isPathInside, readRegularFile, statRegularFile } from "./fs-utils.js";
|
||||
import {
|
||||
isFileMissingError,
|
||||
isPathInside,
|
||||
readRegularFile,
|
||||
root,
|
||||
statRegularFile,
|
||||
} from "./fs-utils.js";
|
||||
import { isMemoryPath, normalizeExtraMemoryPaths } from "./internal.js";
|
||||
import {
|
||||
buildMemoryReadResult,
|
||||
@@ -66,6 +72,17 @@ export async function readMemoryFile(params: {
|
||||
if (!absPath.endsWith(".md")) {
|
||||
throw new Error("path required");
|
||||
}
|
||||
if (allowedWorkspace) {
|
||||
try {
|
||||
const workspaceRoot = await root(params.workspaceDir);
|
||||
await workspaceRoot.resolve(relPath);
|
||||
} catch (err) {
|
||||
if (isFileMissingError(err)) {
|
||||
return { text: "", path: relPath };
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
const statResult = await statRegularFile(absPath);
|
||||
if (statResult.missing) {
|
||||
return { text: "", path: relPath };
|
||||
|
||||
Reference in New Issue
Block a user