Skip to content

Commit c702308

Browse files
committed
fix(windows): sync lock
1 parent f73ecf7 commit c702308

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

lib/common/file-system.ts

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

421421
public rename(oldPath: string, newPath: string): void {
422-
// On Windows, OneDrive / AV scanners can briefly lock a newly-created
422+
// On Windows, AV scanners can briefly lock a newly-created
423423
// directory, causing a transient EPERM on rename. Retry with backoff.
424424
const maxAttempts = 5;
425425
const delayMs = 200;
@@ -432,6 +432,15 @@ export class FileSystem implements IFileSystem {
432432
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, delayMs * attempt);
433433
continue;
434434
}
435+
// If a sync lock on newly-created directories long enough
436+
// that rename never succeeds even after retries. Fall back to a
437+
// recursive copy + delete, which doesn't require an atomic rename and
438+
// is immune to the lock (individual file reads/writes still succeed).
439+
if (e.code === "EPERM" && process.platform === "win32") {
440+
this.copyFile(oldPath, newPath);
441+
this.deleteDirectory(oldPath);
442+
return;
443+
}
435444
throw e;
436445
}
437446
}

0 commit comments

Comments
 (0)