From 0b2fcd1bcda96de7ac9bf27ecf8a9f21810fd7a2 Mon Sep 17 00:00:00 2001 From: Emily Date: Sun, 10 Nov 2024 09:37:26 +0000 Subject: [PATCH] libstore: simplify `makeTemp{,Sibling}Path` callers There is now no risk of race conditions on a system with a functioning entropy source, and the bespoke prefixes are either redundant to the default or unnecessary. Change-Id: I6a6a69641211c6bb979ea48ad30aecb1a53d03f0 --- lix/libstore/build/derivation-goal.cc | 6 +----- lix/libstore/gc.cc | 2 +- lix/libstore/optimise-store.cc | 3 +-- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lix/libstore/build/derivation-goal.cc b/lix/libstore/build/derivation-goal.cc index 57f7c5b99..7359f8c67 100644 --- a/lix/libstore/build/derivation-goal.cc +++ b/lix/libstore/build/derivation-goal.cc @@ -769,11 +769,7 @@ void replaceValidPath(const Path & storePath, const Path & tmpPath) we're repairing (say) Glibc, we end up with a broken system. */ Path oldPath; if (pathExists(storePath)) { - do { - oldPath = makeTempSiblingPath(storePath); - // store paths are often directories so we can't just unlink() it - // let's make sure the path doesn't exist before we try to use it - } while (pathExists(oldPath)); + oldPath = makeTempSiblingPath(storePath); movePath(storePath, oldPath); } diff --git a/lix/libstore/gc.cc b/lix/libstore/gc.cc index 0decc377f..9169efcc6 100644 --- a/lix/libstore/gc.cc +++ b/lix/libstore/gc.cc @@ -98,7 +98,7 @@ void LocalStore::createTempRootsFile() /* Create the temporary roots file for this process. */ while (true) { - auto tmp = makeTempPath(fnTempRoots, ".tmp"); + auto tmp = makeTempPath(fnTempRoots); AutoCloseFD fd{sys::open(tmp, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0600)}; if (!fd && errno != EEXIST) { throw SysError("opening lock file '%1%'", tmp); diff --git a/lix/libstore/optimise-store.cc b/lix/libstore/optimise-store.cc index 1a940800c..3429fbf2d 100644 --- a/lix/libstore/optimise-store.cc +++ b/lix/libstore/optimise-store.cc @@ -227,8 +227,7 @@ std::optional LocalStore::optimisePath_( its timestamp back to 0. */ MakeReadOnly makeReadOnly(mustToggle ? dirOfPath : ""); - Path tempLink = makeTempPath(config().realStoreDir, "/.tmp-link"); - (void) sys::unlink(tempLink); // just in case; ignore errors + Path tempLink = makeTempPath(config().realStoreDir + "/"); if (sys::link(linkPath, tempLink) == -1) { if (errno == EMLINK) {