Skip to content

Commit b35793e

Browse files
committed
windows - wait to file to unlock for removal
while removing dir or file, it happens that EBUSY error could happen with file being used and lock. This is a simple way to wait for file to be unlocked, with a fail safe of max try to avoid infinite loop.
1 parent a5b92f9 commit b35793e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/core/path.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ export function safeRemoveIfExists(file: string) {
4444
}
4545
}
4646

47+
export function safeRemoveSync(
48+
file: string,
49+
options: Deno.RemoveOptions = {},
50+
) {
51+
try {
52+
Deno.removeSync(file, options);
53+
} catch (e) {
54+
if (existsSync(file)) {
55+
throw e;
56+
}
57+
}
58+
}
59+
4760
export function removeIfEmptyDir(dir: string): boolean {
4861
if (existsSync(dir)) {
4962
let empty = true;

0 commit comments

Comments
 (0)