diff --git a/pkgs/build-support/node/import-npm-lock/hooks/link-node-modules.js b/pkgs/build-support/node/import-npm-lock/hooks/link-node-modules.js index 79e247eb4acb..b045e4e0918c 100644 --- a/pkgs/build-support/node/import-npm-lock/hooks/link-node-modules.js +++ b/pkgs/build-support/node/import-npm-lock/hooks/link-node-modules.js @@ -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); }) );