Skip to content

Commit

Permalink
patch: add graceful rename as error handling for windows
Browse files Browse the repository at this point in the history
disucssion: nodejs/node#29481
  • Loading branch information
beenotung committed Apr 1, 2024
1 parent d25be90 commit 61e2daa
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions server/app/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,24 @@ function saveNumber(file: string, value: number) {
value,
error,
})
} else {
return
}
let retry = 5
commit()
function commit() {
rename(tmpfile, file, error => {
if (error) {
log('Failed to commit number to file:', {
tmpfile,
file,
value,
error,
})
if (!error) return
if (error.code == 'EPERM' && retry > 0) {
retry--
setTimeout(commit, 100)
return
}
log('Failed to commit number to file:', {
tmpfile,
file,
value,
error,
})
})
}
})
Expand Down

0 comments on commit 61e2daa

Please sign in to comment.