1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-14 21:11:04 +01:00

libstore: fix race condition when creating state directories

Running parallel nix in nix can lead to multiple instances trying to
create the state directories and failing on the `createSymlink` step,
because the link already exists.

`replaceSymlink` is already idempotent, so let's use that.

Resolves #2706

(cherry picked from commit d64c922164)
This commit is contained in:
Wolfgang Walther 2025-06-17 08:45:29 +02:00 committed by Mergify
parent bab4e58a5e
commit e52fe2cab4

View file

@ -126,7 +126,7 @@ LocalStore::LocalStore(std::string_view scheme, PathView path, const Params & pa
Path gcRootsDir = stateDir + "/gcroots";
if (!pathExists(gcRootsDir)) {
createDirs(gcRootsDir);
createSymlink(profilesDir, gcRootsDir + "/profiles");
replaceSymlink(profilesDir, gcRootsDir + "/profiles");
}
for (auto & perUserDir : {profilesDir + "/per-user", gcRootsDir + "/per-user"}) {