Skip to content
Merged
Changes from 4 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
30 changes: 29 additions & 1 deletion sources/corepackUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ 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`) {
await renameUnderWindows(tmpFolder, installFolder);
} else {
await fs.promises.rename(tmpFolder, installFolder);
}
} catch (err) {
if (
(err as nodeUtils.NodeError).code === `ENOTEMPTY` ||
Expand Down Expand Up @@ -260,6 +264,30 @@ export async function installVersion(installTarget: string, locator: Locator, {s
};
}

async function renameUnderWindows(oldPath: fs.PathLike, newPath: fs.PathLike) {
// Windows malicious file analysis blocks files after download so we need to wait for file release
Comment thread
merceyz marked this conversation as resolved.
Outdated
const retries = 5;
for (let i = 0; i < retries; i++) {
try {
await fs.promises.rename(oldPath, newPath);
break;
} catch (err) {
if (
(
(err as nodeUtils.NodeError).code === `ENOENT` ||
(err as nodeUtils.NodeError).code === `EPERM`
) &&
i < (retries - 1)
) {
await new Promise(resolve => setTimeout(resolve, 100));
Comment thread
aduh95 marked this conversation as resolved.
Outdated
continue;
} else {
throw err;
}
}
}
}

/**
* Loads the binary, taking control of the current process.
*/
Expand Down