@samitouri / QOSami-HFS / commits / 7997478c

fix: some uploads may fail with error EBUSY caused by an antivirus

Massimo Melina committed Feb 13, 2026 at 00:21 UTC 7997478ce85dfbee8e7bde7b879481b46a52210f
1 file changed +6 -2
src/upload.ts
+6 -2
@@ -8,7 +8,7 @@ import { basename, dirname, extname, join } from 'path'
8 import fs from 'fs'
9 import {
10 isValidFileName, loadFileAttr, pendingPromise, storeFileAttr, try_, createStreamLimiter, pathEncode,
11 - enforceFinal, Timeout,
11 + enforceFinal, Timeout, waitFor,
12 } from './misc'
13 import { defineConfig } from './config'
14 import { getDiskSpaceSync } from './util-os'
@@ -192,7 +192,11 @@ export function uploadWriter(base: VfsNode, baseUri: string, filename: string, c
192 while (fs.existsSync(dest))
193 }
194 try {
195 - await rename(tempName, dest)
195 + const done = await waitFor( // an antivirus may lock the temp file to scan it
196 + () => rename(tempName, dest).then(() => true, e => e?.code !== 'EBUSY' && Promise.reject(e)),
197 + { timeout: 10_000 })
198 + if (!done)
199 + throw 'EBUSY'
200 if (mtime) // so we use it to touch the file
201 await utimes(dest, Date.now() / 1000, mtime / 1000)
202 cancelDeletion(tempName) // not necessary, as deletion's failure is silent, but still