diff --git a/src/libstore/ssh.cc b/src/libstore/ssh.cc index d29734a3e..c8fec5244 100644 --- a/src/libstore/ssh.cc +++ b/src/libstore/ssh.cc @@ -34,7 +34,7 @@ SSHMaster::SSHMaster( throw Error("invalid SSH host name '%s'", host); auto state(state_.lock()); - state->tmpDir = std::make_unique(createTempDir("", "nix", true, true, 0700)); + state->tmpDir = std::make_unique(createTempDir("", "nix", 0700)); } void SSHMaster::addCommonSSHOpts(Strings & args) diff --git a/src/libstore/unix/build/derivation-builder.cc b/src/libstore/unix/build/derivation-builder.cc index f107f7a5d..81e0a2584 100644 --- a/src/libstore/unix/build/derivation-builder.cc +++ b/src/libstore/unix/build/derivation-builder.cc @@ -1,4 +1,5 @@ #include "nix/store/build/derivation-builder.hh" +#include "nix/util/file-system.hh" #include "nix/store/local-store.hh" #include "nix/util/processes.hh" #include "nix/store/builtins.hh" @@ -879,7 +880,7 @@ void DerivationBuilderImpl::startBuilder() /* Create a temporary directory where the build will take place. */ - topTmpDir = createTempDir(settings.buildDir.get().value_or(""), "nix-build-" + std::string(drvPath.name()), false, false, 0700); + topTmpDir = createTempDir(settings.buildDir.get().value_or(""), "nix-build-" + std::string(drvPath.name()), 0700); #ifdef __APPLE__ if (false) { #else diff --git a/src/libutil/file-system.cc b/src/libutil/file-system.cc index 06c9a8c1f..103fe11b8 100644 --- a/src/libutil/file-system.cc +++ b/src/libutil/file-system.cc @@ -578,26 +578,11 @@ std::string defaultTempDir() { return getEnvNonEmpty("TMPDIR").value_or("/tmp"); } -static Path tempName(Path tmpRoot, const Path & prefix, bool includePid, - std::atomic & counter) +Path createTempDir(const Path & tmpRoot, const Path & prefix, mode_t mode) { - tmpRoot = canonPath(tmpRoot.empty() ? defaultTempDir() : tmpRoot, true); - if (includePid) - return fmt("%1%/%2%-%3%-%4%", tmpRoot, prefix, getpid(), counter++); - else - return fmt("%1%/%2%-%3%", tmpRoot, prefix, counter++); -} - -Path createTempDir(const Path & tmpRoot, const Path & prefix, - bool includePid, bool useGlobalCounter, mode_t mode) -{ - static std::atomic globalCounter = 0; - std::atomic localCounter = 0; - auto & counter(useGlobalCounter ? globalCounter : localCounter); - while (1) { checkInterrupt(); - Path tmpDir = tempName(tmpRoot, prefix, includePid, counter); + Path tmpDir = makeTempPath(tmpRoot, prefix); if (mkdir(tmpDir.c_str() #ifndef _WIN32 // TODO abstract mkdir perms for Windows , mode diff --git a/src/libutil/include/nix/util/file-system.hh b/src/libutil/include/nix/util/file-system.hh index 02af5b37b..b4cc1567d 100644 --- a/src/libutil/include/nix/util/file-system.hh +++ b/src/libutil/include/nix/util/file-system.hh @@ -310,8 +310,8 @@ typedef std::unique_ptr AutoCloseDir; /** * Create a temporary directory. */ -Path createTempDir(const Path & tmpRoot = "", const Path & prefix = "nix", - bool includePid = true, bool useGlobalCounter = true, 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.