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

Fix Windows malicious file analysis waiting problem #398

Merged
merged 7 commits into from
Feb 27, 2024
26 changes: 25 additions & 1 deletion sources/corepackUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,31 @@ export async function installVersion(installTarget: string, locator: Locator, {s

await fs.promises.mkdir(path.dirname(installFolder), {recursive: true});
try {
await fs.promises.rename(tmpFolder, installFolder);
if (process.platform === "win32") {
// Windows malicious file analysis blocks files after download so we need to wait for file release
const retries = 5;
for (let i = 0; i < retries; i++) {
try {
await fs.promises.rename(tmpFolder, installFolder);
break;
} catch (err) {
if (
(
(err as nodeUtils.NodeError).code === `ENOENT` ||
(err as nodeUtils.NodeError).code === "EPERM"
ngnlTeto marked this conversation as resolved.
Show resolved Hide resolved
) &&
i < (retries - 1)
) {
await new Promise(resolve => setTimeout(resolve, 100));
continue;
} else {
throw err;
}
}
}
} else {
await fs.promises.rename(tmpFolder, installFolder);
}
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
} catch (err) {
if (
(err as nodeUtils.NodeError).code === `ENOTEMPTY` ||
Expand Down