mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
refactor: move directory creation before lock file operations. fix #6
This commit is contained in:
@@ -74,6 +74,10 @@ export async function updateSettings(
|
||||
const MAX_LOCK_ATTEMPTS = 50; // Maximum number of attempts (5 seconds total)
|
||||
const STALE_LOCK_TIMEOUT_MS = 10000; // Consider lock stale after 10 seconds
|
||||
|
||||
if (!existsSync(configuration.happyHomeDir)) {
|
||||
await mkdir(configuration.happyHomeDir, { recursive: true });
|
||||
}
|
||||
|
||||
const lockFile = configuration.settingsFile + '.lock';
|
||||
const tmpFile = configuration.settingsFile + '.tmp';
|
||||
let fileHandle;
|
||||
@@ -115,11 +119,6 @@ export async function updateSettings(
|
||||
// Apply update
|
||||
const updated = await updater(current);
|
||||
|
||||
// Ensure directory exists
|
||||
if (!existsSync(configuration.happyHomeDir)) {
|
||||
await mkdir(configuration.happyHomeDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Write atomically using rename
|
||||
await writeFile(tmpFile, JSON.stringify(updated, null, 2));
|
||||
await rename(tmpFile, configuration.settingsFile); // Atomic on POSIX
|
||||
|
||||
Reference in New Issue
Block a user