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 (#1067)

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 authored Nov 27, 2024
1 parent 27e3d46 commit 01bbece
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 @@ -688,10 +688,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 01bbece

Please sign in to comment.