Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/deno_ral/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { fromFileUrl } from "./path.ts";
import { resolve, SEP as SEPARATOR } from "./path.ts";
import { copySync } from "fs/copy";
import { existsSync } from "fs/exists";
import { isWindows } from "./platform.ts";

export { ensureDir, ensureDirSync } from "fs/ensure-dir";
export { existsSync } from "fs/exists";
Expand Down Expand Up @@ -100,8 +101,25 @@ export function safeRemoveSync(
try {
Deno.removeSync(file, options);
} catch (e) {
let lastError = e;
// WINDOWS ONLY: Retry on windows to let time to file to unlock
if (isWindows && e.code === "EBUSY") {
let nTry: number = 1;
// high number to prevent infinite loop
const maxTry: number = 500;
let eCode = e.code;
while (eCode === "EBUSY" && nTry <= maxTry) {
try {
Deno.removeSync(file, options);
} catch (e) {
lastError = e;
eCode = e.code;
nTry++;
}
}
}
if (existsSync(file)) {
throw e;
throw lastError;
}
}
}
Expand Down
Loading