fix: stabilize windows temp and path handling

This commit is contained in:
Tak Hoffman
2026-03-18 23:27:50 -05:00
parent afa95fade0
commit 3abffe0967
4 changed files with 18 additions and 4 deletions

View File

@@ -115,13 +115,20 @@ function loadHookFromDir(params: {
return null;
}
let baseDir = params.hookDir;
try {
baseDir = fs.realpathSync.native(params.hookDir);
} catch {
// keep the discovered path when realpath is unavailable
}
return {
name,
description,
source: params.source,
pluginId: params.pluginId,
filePath: hookMdPath,
baseDir: params.hookDir,
baseDir,
handlerPath,
};
} catch (err) {

View File

@@ -1,5 +1,5 @@
import fs from "node:fs";
import os from "node:os";
import { tmpdir as getOsTmpDir } from "node:os";
import path from "node:path";
export const POSIX_OPENCLAW_TMP_DIR = "/tmp/openclaw";
@@ -48,7 +48,7 @@ export function resolvePreferredOpenClawTmpDir(
return undefined;
}
});
const tmpdir = options.tmpdir ?? os.tmpdir;
const tmpdir = typeof options.tmpdir === "function" ? options.tmpdir : getOsTmpDir;
const uid = getuid();
const isSecureDirForUser = (st: { mode?: number; uid?: number }): boolean => {

View File

@@ -35,8 +35,14 @@ function resolveDefaultLogDir(): string {
return canUseNodeFs() ? resolvePreferredOpenClawTmpDir() : POSIX_OPENCLAW_TMP_DIR;
}
function resolveDefaultLogFile(defaultLogDir: string): string {
return canUseNodeFs()
? path.join(defaultLogDir, "openclaw.log")
: `${POSIX_OPENCLAW_TMP_DIR}/openclaw.log`;
}
export const DEFAULT_LOG_DIR = resolveDefaultLogDir();
export const DEFAULT_LOG_FILE = path.join(DEFAULT_LOG_DIR, "openclaw.log"); // legacy single-file path
export const DEFAULT_LOG_FILE = resolveDefaultLogFile(DEFAULT_LOG_DIR); // legacy single-file path
const LOG_PREFIX = "openclaw";
const LOG_SUFFIX = ".log";

View File

@@ -70,6 +70,7 @@ const RUNTIME_API_EXPORT_GUARDS: Record<string, readonly string[]> = {
'export * from "./src/auto-reply.js";',
'export * from "./src/inbound.js";',
'export * from "./src/login.js";',
'export * from "./src/login-qr.js";',
'export * from "./src/media.js";',
'export * from "./src/send.js";',
'export * from "./src/session.js";',