惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
博客园 - 叶小钗
The Cloudflare Blog
D
DataBreaches.Net
J
Java Code Geeks
G
Google Developers Blog
L
LangChain Blog
N
Netflix TechBlog - Medium
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
小众软件
小众软件
量子位
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
博客园_首页
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog
腾讯CDC

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor: share file transfer node host path handling · o...
vincentkoc · 2026-05-29 · via Recent Commits to openclaw:main
11

import { spawn } from "node:child_process";

22

import crypto from "node:crypto";

3-

import fs from "node:fs/promises";

43

import path from "node:path";

4+

import { root as fsRoot } from "openclaw/plugin-sdk/security-runtime";

55

import {

6-

FsSafeError,

7-

resolveAbsolutePathForRead,

8-

root as fsRoot,

9-

} from "openclaw/plugin-sdk/security-runtime";

6+

classifyFsSafeReadError,

7+

readAbsolutePath,

8+

resolveCanonicalReadPath,

9+

statRequiredDirectory,

10+

} from "./path-errors.js";

10111112

const DIR_FETCH_HARD_MAX_BYTES = 16 * 1024 * 1024;

1213

const DIR_FETCH_DEFAULT_MAX_BYTES = 8 * 1024 * 1024;

@@ -55,16 +56,9 @@ function clampMaxBytes(input: unknown): number {

5556

}

56575758

function classifyFsError(err: unknown): DirFetchErrCode {

58-

if (err instanceof FsSafeError) {

59-

if (err.code === "not-found") {

60-

return "NOT_FOUND";

61-

}

62-

if (err.code === "symlink") {

63-

return "SYMLINK_REDIRECT";

64-

}

65-

if (err.code === "invalid-path") {

66-

return "INVALID_PATH";

67-

}

59+

const safeCode = classifyFsSafeReadError(err);

60+

if (safeCode) {

61+

return safeCode;

6862

}

6963

const code = (err as { code?: string } | null)?.code;

7064

if (code === "ENOENT") {

@@ -184,67 +178,29 @@ async function listTreeEntries(root: string, maxEntries: number): Promise<string

184178

}

185179186180

export async function handleDirFetch(params: DirFetchParams): Promise<DirFetchResult> {

187-

const requestedPath = params.path;

188-

if (typeof requestedPath !== "string" || requestedPath.length === 0) {

189-

return { ok: false, code: "INVALID_PATH", message: "path required" };

190-

}

191-

if (requestedPath.includes("\0")) {

192-

return { ok: false, code: "INVALID_PATH", message: "path contains NUL byte" };

193-

}

194-

if (!path.isAbsolute(requestedPath)) {

195-

return { ok: false, code: "INVALID_PATH", message: "path must be absolute" };

181+

const requestedPath = readAbsolutePath(params.path);

182+

if (typeof requestedPath !== "string") {

183+

return requestedPath;

196184

}

197185198186

const maxBytes = clampMaxBytes(params.maxBytes);

199187

const includeDotfiles = params.includeDotfiles === true;

200188

const followSymlinks = params.followSymlinks === true;

201189

const preflightOnly = params.preflightOnly === true;

202190203-

let canonical: string;

204-

try {

205-

canonical = (

206-

await resolveAbsolutePathForRead(requestedPath, {

207-

symlinks: followSymlinks ? "follow" : "reject",

208-

})

209-

).canonicalPath;

210-

} catch (err) {

211-

const code = classifyFsError(err);

212-

const canonicalPath =

213-

err instanceof FsSafeError &&

214-

err.cause &&

215-

typeof err.cause === "object" &&

216-

"canonicalPath" in err.cause &&

217-

typeof err.cause.canonicalPath === "string"

218-

? err.cause.canonicalPath

219-

: undefined;

220-

return {

221-

ok: false,

222-

code,

223-

message:

224-

code === "NOT_FOUND"

225-

? "directory not found"

226-

: code === "SYMLINK_REDIRECT"

227-

? "path traverses a symlink; refusing because followSymlinks=false (set plugins.entries.file-transfer.config.nodes.<node>.followSymlinks=true to allow, or update allowReadPaths to the canonical path)"

228-

: `realpath failed: ${String(err)}`,

229-

...(canonicalPath ? { canonicalPath } : {}),

230-

};

231-

}

232-233-

let stats: Awaited<ReturnType<typeof fs.stat>>;

234-

try {

235-

stats = await fs.stat(canonical);

236-

} catch (err) {

237-

const code = classifyFsError(err);

238-

return { ok: false, code, message: `stat failed: ${String(err)}`, canonicalPath: canonical };

191+

const canonical = await resolveCanonicalReadPath({

192+

requestedPath,

193+

followSymlinks,

194+

classifyError: classifyFsError,

195+

notFoundMessage: "directory not found",

196+

});

197+

if (typeof canonical !== "string") {

198+

return canonical;

239199

}

240200241-

if (!stats.isDirectory()) {

242-

return {

243-

ok: false,

244-

code: "IS_FILE",

245-

message: "path is not a directory",

246-

canonicalPath: canonical,

247-

};

201+

const directory = await statRequiredDirectory(canonical, classifyFsError);

202+

if (!directory.ok) {

203+

return directory;

248204

}

249205250206

if (preflightOnly) {