From e3ff4e0365fcd06f0ac7406f7a1b4299bff2e27e Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Thu, 21 Aug 2025 14:36:10 +0000 Subject: [PATCH] Revert "libstore: simplify `createTempDir` interface" Revert submission 3850 Reason for revert: caused multiple regressions noticed in https://git.lix.systems/lix-project/lix/issues/975 and https://git.lix.systems/lix-project/lix/issues/966 (suspected). Root cause analysis has not been done yet and this breaks Lix on Darwin on HEAD. Reverted changes: /q/submissionid:3850 Change-Id: I76930bdc1fb51edb5b0c591272ecb6f69085f197 --- lix/legacy/nix-build.cc | 2 +- lix/libstore/build/local-derivation-goal.cc | 8 +++++--- lix/libstore/local-store.cc | 2 +- lix/libstore/ssh.cc | 2 +- lix/libstore/temporary-dir.cc | 4 ++-- lix/libstore/temporary-dir.hh | 2 +- lix/nix/develop.cc | 4 ++-- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lix/legacy/nix-build.cc b/lix/legacy/nix-build.cc index fa7f3d0ec..240721539 100644 --- a/lix/legacy/nix-build.cc +++ b/lix/legacy/nix-build.cc @@ -187,7 +187,7 @@ static void main_nix_build(AsyncIoRoot & aio, std::string programName, Strings a if (packages && fromArgs) throw UsageError("'-p' and '-E' are mutually exclusive"); - AutoDelete tmpDir(createTempDir(myName)); + AutoDelete tmpDir(createTempDir("", myName)); if (outLink.empty()) outLink = (Path) tmpDir + "/result"; diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index 7b5d9a141..c4947504c 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -447,7 +447,7 @@ try { /* Create a temporary directory where the build will take place. */ tmpDirRoot = - createTempSubdir(buildDir, "nix-build-" + std::string(drvPath.name()), 0700); + createTempDir(buildDir, "nix-build-" + std::string(drvPath.name()), 0700); } catch (SysError & e) { /* * Fallback to the global tmpdir and create a safe space there @@ -465,14 +465,16 @@ try { #else constexpr int toplevelDirMode = 0700; #endif - auto nixBuildsTmp = createTempDir(fmt("nix-builds-%s", geteuid()), toplevelDirMode); + auto nixBuildsTmp = createTempDir( + "", fmt("nix-builds-%s", geteuid()), toplevelDirMode + ); warn( "Failed to use the system-wide build directory '%s', falling back to a temporary " "directory inside '%s'", settings.buildDir.get(), nixBuildsTmp ); - tmpDirRoot = createTempSubdir( + tmpDirRoot = createTempDir( nixBuildsTmp, "nix-build-" + std::string(drvPath.name()), 0700 ); worker.buildDirOverride = nixBuildsTmp; diff --git a/lix/libstore/local-store.cc b/lix/libstore/local-store.cc index 7a8fe1b58..c75001e4f 100644 --- a/lix/libstore/local-store.cc +++ b/lix/libstore/local-store.cc @@ -1401,7 +1401,7 @@ std::pair LocalStore::createTempDirInStore() /* There is a slight possibility that `tmpDir' gets deleted by the GC between createTempDir() and when we acquire a lock on it. We'll repeat until 'tmpDir' exists and we've locked it. */ - tmpDirFn = createTempSubdir(config_.realStoreDir, "tmp"); + tmpDirFn = createTempDir(config_.realStoreDir, "tmp"); tmpDirFd = AutoCloseFD{open(tmpDirFn.c_str(), O_RDONLY | O_DIRECTORY)}; if (tmpDirFd.get() < 0) { continue; diff --git a/lix/libstore/ssh.cc b/lix/libstore/ssh.cc index 17c7db29b..a7b48a330 100644 --- a/lix/libstore/ssh.cc +++ b/lix/libstore/ssh.cc @@ -25,7 +25,7 @@ SSH::SSH(const std::string & host, const std::optional port, const std throw Error("invalid SSH host name '%s'", host); auto state(state_.lock()); - state->tmpDir = std::make_unique(createTempDir("nix", 0700)); + state->tmpDir = std::make_unique(createTempDir("", "nix", 0700)); } void SSH::addCommonSSHOpts(Strings & args) diff --git a/lix/libstore/temporary-dir.cc b/lix/libstore/temporary-dir.cc index 795e55d29..2e601e34c 100644 --- a/lix/libstore/temporary-dir.cc +++ b/lix/libstore/temporary-dir.cc @@ -5,9 +5,9 @@ namespace nix { -Path createTempDir(const Path & prefix, mode_t mode) +Path createTempDir(const Path & tmpRoot, const Path & prefix, mode_t mode) { - return createTempSubdir(defaultTempDir(), prefix, mode); + return createTempSubdir(tmpRoot.empty() ? defaultTempDir() : tmpRoot, prefix, mode); } std::pair createTempFile(const Path & prefix) diff --git a/lix/libstore/temporary-dir.hh b/lix/libstore/temporary-dir.hh index a2a8a0d18..9bc4df9c4 100644 --- a/lix/libstore/temporary-dir.hh +++ b/lix/libstore/temporary-dir.hh @@ -8,7 +8,7 @@ namespace nix { /** * Create a temporary directory. */ -Path createTempDir(const Path & prefix = "nix", mode_t mode = 0755); +Path createTempDir(const Path & tmpRoot = "", const Path & prefix = "nix", mode_t mode = 0755); /** * Create a temporary file, returning a file handle and its path. diff --git a/lix/nix/develop.cc b/lix/nix/develop.cc index 47e35d907..dfbc09b95 100644 --- a/lix/nix/develop.cc +++ b/lix/nix/develop.cc @@ -552,7 +552,7 @@ struct CmdDevelop : Common, MixEnvironment auto [rcFileFd, rcFilePath] = createTempFile("nix-shell"); - AutoDelete tmpDir(createTempDir("nix-develop"), true); + AutoDelete tmpDir(createTempDir("", "nix-develop"), true); auto script = makeRcScript(*state, store, buildEnvironment, (Path) tmpDir); @@ -689,7 +689,7 @@ struct CmdPrintDevEnv : Common, MixJSON if (json) { logger->writeToStdout(buildEnvironment.toJSON()); } else { - AutoDelete tmpDir(createTempDir("nix-dev-env"), true); + AutoDelete tmpDir(createTempDir("", "nix-dev-env"), true); logger->writeToStdout(makeRcScript(*state, store, buildEnvironment, tmpDir)); } }