Skip to content

Commit

Permalink
fix(server/settings): write settings to a temp file then move to avoi…
Browse files Browse the repository at this point in the history
…d corruption

When writing the settings.json file ensure that the file is fully written by writing it to temporary
file before renaming it to the final settings path. This should prevent issues where the config gets
lost due to the file being corrupted.
  • Loading branch information
Zariel committed Nov 1, 2024
1 parent ca838a0 commit 9452f08
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions server/lib/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,10 +682,9 @@ class Settings {
}

public async save(): Promise<void> {
await fs.writeFile(
SETTINGS_PATH,
JSON.stringify(this.data, undefined, ' ')
);
const tmp = SETTINGS_PATH + '.tmp';
await fs.writeFile(tmp, JSON.stringify(this.data, undefined, ' '));
await fs.rename(tmp, SETTINGS_PATH);
}
}

Expand Down

0 comments on commit 9452f08

Please sign in to comment.