mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 10:11:24 +00:00
fix: execute sandboxed file ops inside containers (#4026)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 795ec6aa2f
Co-authored-by: davidbors-snyk <240482518+davidbors-snyk@users.noreply.github.com>
Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
Reviewed-by: @steipete
This commit is contained in:
@@ -7,11 +7,17 @@ type UpdateFileChunk = {
|
||||
isEndOfFile: boolean;
|
||||
};
|
||||
|
||||
async function defaultReadFile(filePath: string): Promise<string> {
|
||||
return fs.readFile(filePath, "utf8");
|
||||
}
|
||||
|
||||
export async function applyUpdateHunk(
|
||||
filePath: string,
|
||||
chunks: UpdateFileChunk[],
|
||||
options?: { readFile?: (filePath: string) => Promise<string> },
|
||||
): Promise<string> {
|
||||
const originalContents = await fs.readFile(filePath, "utf8").catch((err) => {
|
||||
const reader = options?.readFile ?? defaultReadFile;
|
||||
const originalContents = await reader(filePath).catch((err) => {
|
||||
throw new Error(`Failed to read file to update ${filePath}: ${err}`);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user