importNpmLock: Don't create intermediate symlink files (#425009)
This commit is contained in:
commit
2f9b4fe37e
@ -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);
|
||||
})
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user