@samitouri / QOSami-HFS / commits / 9d8d855b

fix: rare upload failure in case of existing temporary file

Massimo Melina committed Jul 4, 2025 at 14:22 UTC 9d8d855b0c688916df8970bd3666b2a94227c746
1 file changed +2 -2
src/upload.ts
+2 -2
@@ -19,7 +19,7 @@ import { getCurrentUsername } from './auth'
19 import { setCommentFor } from './comments'
20 import _ from 'lodash'
21 import events from './events'
22 -import { rename, rm } from 'fs/promises'
22 +import { rm } from 'fs/promises'
23 import { expiringCache } from './expiringCache'
24 import { onProcessExit } from './first'
25 import { once, Transform } from 'stream'
@@ -216,7 +216,7 @@ export function uploadWriter(base: VfsNode, baseUri: string, path: string, ctx:
216 while (fs.existsSync(dest))
217 }
218 try {
219 - await rename(tempName, dest)
219 + fs.renameSync(tempName, dest) // sync to avoid race conditions with checkIfNewUploadBecameLargerThanResumable
220 const t = Number(ctx.query.giveBack) // we know giveBack contains lastModified in ms
221 if (t) // so we use it to touch the file
222 await utimes(dest, Date.now() / 1000, t / 1000)