Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows - wait to file to unlock for removal #10629

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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/core/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as ld from "./lodash.ts";

import { getenv } from "./env.ts";
import { execProcess } from "./process.ts";
import { isWindows } from "./platform.ts";

export const kSkipHidden = /[/\\][\.]/;

Expand All @@ -50,8 +51,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