fix(config): preserve existing nested config dir before short-circuiting
When OPENCLAW_HOME basename matches a known state dir name, the nesting guard now checks whether a nested .openclaw subdirectory already exists before returning the parent. This preserves backward compatibility for installs that previously wrote config data into the (now-prevented) nested path. Adds test to verify the backward compat behavior.
This commit is contained in:
parent
9e38b064e9
commit
14fb5801c5
@ -159,6 +159,18 @@ describe("resolveConfigDir", () => {
|
||||
const env = { OPENCLAW_HOME: "/srv/app" } as NodeJS.ProcessEnv;
|
||||
expect(resolveConfigDir(env)).toBe(path.resolve("/srv/app/.openclaw"));
|
||||
});
|
||||
|
||||
it("prefers existing nested config dir for backward compat (#45765)", () => {
|
||||
const tmpDir = path.join(os.tmpdir(), `openclaw-test-config-${Date.now()}`);
|
||||
const nestedDir = path.join(tmpDir, ".openclaw", ".openclaw");
|
||||
fs.mkdirSync(nestedDir, { recursive: true });
|
||||
try {
|
||||
const env = { OPENCLAW_HOME: path.join(tmpDir, ".openclaw") } as NodeJS.ProcessEnv;
|
||||
expect(resolveConfigDir(env)).toBe(path.join(tmpDir, ".openclaw", ".openclaw"));
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveHomeDir", () => {
|
||||
|
||||
10
src/utils.ts
10
src/utils.ts
@ -295,6 +295,16 @@ export function resolveConfigDir(
|
||||
const explicitHome = env.OPENCLAW_HOME?.trim();
|
||||
const resolvedHome = resolveRequiredHomeDir(env, homedir);
|
||||
if (explicitHome && ALL_STATE_DIRNAMES.has(path.basename(resolvedHome))) {
|
||||
// Backward compat: if a nested config dir already exists from the old
|
||||
// buggy behavior, prefer it so we don't orphan existing config data.
|
||||
const nestedConfig = path.join(resolvedHome, ".openclaw");
|
||||
try {
|
||||
if (fs.existsSync(nestedConfig)) {
|
||||
return nestedConfig;
|
||||
}
|
||||
} catch {
|
||||
// best-effort
|
||||
}
|
||||
return resolvedHome;
|
||||
}
|
||||
const newDir = path.join(resolvedHome, ".openclaw");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user