mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 14:03:49 +00:00
Do not create empty .pi folder unconditionally (#1588)
This commit is contained in:
parent
6137de9ce7
commit
f1a2092bcf
3 changed files with 61 additions and 5 deletions
|
|
@ -147,16 +147,24 @@ export class FileSettingsStorage implements SettingsStorage {
|
|||
withLock(scope: SettingsScope, fn: (current: string | undefined) => string | undefined): void {
|
||||
const path = scope === "global" ? this.globalSettingsPath : this.projectSettingsPath;
|
||||
const dir = dirname(path);
|
||||
if (!existsSync(dir)) {
|
||||
mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
|
||||
let release: (() => void) | undefined;
|
||||
try {
|
||||
release = lockfile.lockSync(path, { realpath: false });
|
||||
const current = existsSync(path) ? readFileSync(path, "utf-8") : undefined;
|
||||
// Only create directory and lock if file exists or we need to write
|
||||
const fileExists = existsSync(path);
|
||||
if (fileExists) {
|
||||
release = lockfile.lockSync(path, { realpath: false });
|
||||
}
|
||||
const current = fileExists ? readFileSync(path, "utf-8") : undefined;
|
||||
const next = fn(current);
|
||||
if (next !== undefined) {
|
||||
// Only create directory when we actually need to write
|
||||
if (!existsSync(dir)) {
|
||||
mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
if (!release) {
|
||||
release = lockfile.lockSync(path, { realpath: false });
|
||||
}
|
||||
writeFileSync(path, next, "utf-8");
|
||||
}
|
||||
} finally {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue