importNpmLock: Don't create intermediate symlink files (#425009)

This commit is contained in:
Philip Taron 2025-07-14 20:51:13 -07:00 committed by GitHub
commit 2f9b4fe37e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -69,19 +69,17 @@ async function main() {
// Don't unlink this file, we just wrote it.
managed.delete(file);
// Link to a temporary dummy path and rename.
// This is to get some degree of atomicity.
// Link file
try {
await fs.promises.symlink(sourcePath, targetPath + "-nix-hook-temp");
await fs.promises.symlink(sourcePath, targetPath);
} catch (err) {
// If the target file already exists remove it and try again
if (err.code !== "EEXIST") {
throw err;
}
await fs.promises.unlink(targetPath + "-nix-hook-temp");
await fs.promises.symlink(sourcePath, targetPath + "-nix-hook-temp");
await fs.promises.unlink(targetPath);
await fs.promises.symlink(sourcePath, targetPath);
}
await fs.promises.rename(targetPath + "-nix-hook-temp", targetPath);
})
);