Skip to content

Commit

Permalink
write files atomically
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicklason committed Apr 18, 2022
1 parent f47bfb3 commit 30abdd4
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 28 deletions.
113 changes: 86 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@tf2autobot/tf2-schema": "^2.4.2",
"@tf2autobot/tf2-sku": "^2.0.3",
"@tf2autobot/tradeoffer-manager": "^2.11.4",
"@types/write-file-atomic": "^4.0.0",
"async": "^3.2.3",
"bluebird": "^3.7.2",
"bluebird-global": "^1.0.1",
Expand Down Expand Up @@ -67,6 +68,7 @@
"websocket-extensions": "^0.1.4",
"winston": "^3.7.2",
"winston-daily-rotate-file": "^4.6.1",
"write-file-atomic": "^4.0.1",
"ws": "^8.5.0",
"xmlhttprequest-ts": "^1.0.1"
},
Expand Down
3 changes: 2 additions & 1 deletion src/lib/files.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs';
import writeFileAtomic from 'write-file-atomic';
import path from 'path';

import { exponentialBackoff } from './helpers';
Expand Down Expand Up @@ -64,7 +65,7 @@ export function writeFile(p: string, data: unknown, json: boolean): Promise<void

function writeToFile(): void {
filesBeingSaved++;
fs.writeFile(p, write, { encoding: 'utf8' }, err => {
writeFileAtomic(p, write, { encoding: 'utf8' }, err => {
filesBeingSaved--;

if (err) {
Expand Down

0 comments on commit 30abdd4

Please sign in to comment.