Do not create empty .pi folder unconditionally (#1588)

This commit is contained in:
Duncan Ogilvie 2026-02-23 00:59:10 +01:00 committed by GitHub
parent 6137de9ce7
commit f1a2092bcf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 61 additions and 5 deletions

View file

@ -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 {