diff --git a/lix/libstore/temporary-dir.cc b/lix/libstore/temporary-dir.cc index 795e55d29..102585e39 100644 --- a/lix/libstore/temporary-dir.cc +++ b/lix/libstore/temporary-dir.cc @@ -5,7 +5,7 @@ namespace nix { -Path createTempDir(const Path & prefix, mode_t mode) +Path createTempDir(const std::optional & prefix, mode_t mode) { return createTempSubdir(defaultTempDir(), prefix, mode); } diff --git a/lix/libstore/temporary-dir.hh b/lix/libstore/temporary-dir.hh index a2a8a0d18..a2a9587b2 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 std::optional & prefix = "nix", mode_t mode = 0755); /** * Create a temporary file, returning a file handle and its path. diff --git a/lix/libutil/file-system.cc b/lix/libutil/file-system.cc index 26ac4fa94..1390925a9 100644 --- a/lix/libutil/file-system.cc +++ b/lix/libutil/file-system.cc @@ -646,7 +646,7 @@ void AutoDelete::reset(const Path & p, bool recursive) { ////////////////////////////////////////////////////////////////////// -Path createTempSubdir(const Path & parent, const Path & prefix, +Path createTempSubdir(const Path & parent, const std::optional & prefix, mode_t mode) { checkInterrupt(); @@ -670,7 +670,7 @@ Path createTempSubdir(const Path & parent, const Path & prefix, throw SysError("creating directory '%1%'", tmpDir); } -Path makeTempPath(const Path & root, const Path & prefix) +Path makeTempPath(const Path & root, const std::optional & prefix) { static thread_local std::random_device generator{}; std::uniform_int_distribution uniform_dist{}; @@ -679,7 +679,11 @@ Path makeTempPath(const Path & root, const Path & prefix) reinterpret_cast(entropy), sizeof(entropy) )); - return fmt("%s%s-%s", root, prefix, unique); + if (prefix) { + return fmt("%s%s-%s", root, *prefix, unique); + } else { + return root + unique; + } } Path makeTempSiblingPath(const Path & path) diff --git a/lix/libutil/file-system.hh b/lix/libutil/file-system.hh index 85af08fdb..f615470fa 100644 --- a/lix/libutil/file-system.hh +++ b/lix/libutil/file-system.hh @@ -307,16 +307,16 @@ typedef std::unique_ptr AutoCloseDir; /** * Create a temporary directory in a given parent directory. */ -Path createTempSubdir(const Path & parent, const Path & prefix = "nix", +Path createTempSubdir(const Path & parent, const std::optional & prefix = "nix", mode_t mode = 0755); /** * Return temporary path constructed by appending to a root path. * - * The constructed path looks like `-`. To create a + * The constructed path looks like `[-]`. To create a * path nested in a directory, provide a root ending with `/`. */ -Path makeTempPath(const Path & root, const Path & prefix = ".tmp"); +Path makeTempPath(const Path & root, const std::optional & prefix = ".tmp"); /** * Return temporary path in the same directory as a given path.