
























@@ -30,8 +30,13 @@ function isNodeErrorWithCode(err: unknown, code: string): err is MaybeNodeError
3030);
3131}
323233+type ResolvePreferredOpenClawTmpDirInternalOptions = ResolvePreferredOpenClawTmpDirOptions & {
34+/** Test seam for the host platform; defaults to `process.platform`. */
35+platform?: NodeJS.Platform;
36+};
37+3338export function resolvePreferredOpenClawTmpDir(
34-options: ResolvePreferredOpenClawTmpDirOptions = {},
39+options: ResolvePreferredOpenClawTmpDirInternalOptions = {},
3540): string {
3641// Evaluated here (not at module load) so this file is safe to import in browser bundles.
3742const TMP_DIR_ACCESS_MODE = fs.constants.W_OK | fs.constants.X_OK;
@@ -50,6 +55,7 @@ export function resolvePreferredOpenClawTmpDir(
5055}
5156});
5257const tmpdir = typeof options.tmpdir === "function" ? options.tmpdir : getOsTmpDir;
58+const platform = options.platform ?? process.platform;
5359const uid = getuid();
54605561const isSecureDirForUser = (st: { mode?: number; uid?: number }): boolean => {
@@ -69,7 +75,11 @@ export function resolvePreferredOpenClawTmpDir(
6975const fallback = (): string => {
7076const base = tmpdir();
7177const suffix = uid === undefined ? "openclaw" : `openclaw-${uid}`;
72-return path.join(base, suffix);
78+// Use the platform-specific joiner so Windows fallbacks stay in pure
79+// backslash form even when the host process is non-Windows (e.g. when
80+// tests inject `platform: "win32"` on a Linux runner).
81+const joiner = platform === "win32" ? path.win32.join : path.join;
82+return joiner(base, suffix);
7383};
74847585const isTrustedTmpDir = (st: {
@@ -155,6 +165,17 @@ export function resolvePreferredOpenClawTmpDir(
155165return fallbackPath;
156166};
157167168+// On Windows, Node resolves the POSIX path `/tmp` to `C:\tmp` (relative to
169+// the current drive root). Many Windows hosts have `C:\tmp` because Git,
170+// MSYS2, and other Unix-compat tools create it; the existing logic then
171+// happily writes logs and TTS files to `C:\tmp\openclaw\` while every
172+// other code path expects `%TEMP%\openclaw\`. Skip the POSIX preferred
173+// path entirely on Windows so the function falls through to the
174+// os.tmpdir() fallback (#60713).
175+if (platform === "win32") {
176+return ensureTrustedFallbackDir();
177+}
178+158179const existingPreferredState = resolveDirState(POSIX_OPENCLAW_TMP_DIR);
159180if (existingPreferredState === "available") {
160181return POSIX_OPENCLAW_TMP_DIR;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。