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
This commit is contained in:
Raito Bezarius
2025-08-21 14:37:46 +00:00
parent e7253d0621
commit e3ff4e0365
7 changed files with 13 additions and 11 deletions
+1 -1
View File
@@ -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";
+5 -3
View File
@@ -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;
+1 -1
View File
@@ -1401,7 +1401,7 @@ std::pair<Path, AutoCloseFD> 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;
+1 -1
View File
@@ -25,7 +25,7 @@ SSH::SSH(const std::string & host, const std::optional<uint16_t> port, const std
throw Error("invalid SSH host name '%s'", host);
auto state(state_.lock());
state->tmpDir = std::make_unique<AutoDelete>(createTempDir("nix", 0700));
state->tmpDir = std::make_unique<AutoDelete>(createTempDir("", "nix", 0700));
}
void SSH::addCommonSSHOpts(Strings & args)
+2 -2
View File
@@ -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<AutoCloseFD, Path> createTempFile(const Path & prefix)
+1 -1
View File
@@ -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.
+2 -2
View File
@@ -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));
}
}