Skip to content

Commit f73ecf7

Browse files
committed
fix: fs rename add retry with backoff
1 parent bc517c0 commit f73ecf7

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

lib/common/file-system.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,22 @@ export class FileSystem implements IFileSystem {
419419
}
420420

421421
public rename(oldPath: string, newPath: string): void {
422-
fs.renameSync(oldPath, newPath);
422+
// On Windows, OneDrive / AV scanners can briefly lock a newly-created
423+
// directory, causing a transient EPERM on rename. Retry with backoff.
424+
const maxAttempts = 5;
425+
const delayMs = 200;
426+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
427+
try {
428+
fs.renameSync(oldPath, newPath);
429+
return;
430+
} catch (e) {
431+
if (e.code === "EPERM" && attempt < maxAttempts) {
432+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, delayMs * attempt);
433+
continue;
434+
}
435+
throw e;
436+
}
437+
}
423438
}
424439

425440
public renameIfExists(oldPath: string, newPath: string): boolean {

0 commit comments

Comments
 (0)