From e7253d06211adeb7ea7c2ba48f0acc9e81600ada Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Thu, 21 Aug 2025 14:36:10 +0000 Subject: [PATCH] Revert "libstore: make temporary path prefixes optional" 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: Ib4d3179cbfa8e9f861d7416fe08f7d7e3a7d55e2 --- lix/libstore/temporary-dir.cc | 2 +- lix/libstore/temporary-dir.hh | 2 +- lix/libutil/file-system.cc | 10 +++------- lix/libutil/file-system.hh | 6 +++--- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lix/libstore/temporary-dir.cc b/lix/libstore/temporary-dir.cc index 102585e39..795e55d29 100644 --- a/lix/libstore/temporary-dir.cc +++ b/lix/libstore/temporary-dir.cc @@ -5,7 +5,7 @@ namespace nix { -Path createTempDir(const std::optional & prefix, mode_t mode) +Path createTempDir(const Path & prefix, mode_t mode) { return createTempSubdir(defaultTempDir(), prefix, mode); } diff --git a/lix/libstore/temporary-dir.hh b/lix/libstore/temporary-dir.hh index a2a9587b2..a2a8a0d18 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 std::optional & prefix = "nix", mode_t mode = 0755); +Path createTempDir(const Path & 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 1390925a9..26ac4fa94 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 std::optional & prefix, +Path createTempSubdir(const Path & parent, const Path & prefix, mode_t mode) { checkInterrupt(); @@ -670,7 +670,7 @@ Path createTempSubdir(const Path & parent, const std::optional & prefix, throw SysError("creating directory '%1%'", tmpDir); } -Path makeTempPath(const Path & root, const std::optional & prefix) +Path makeTempPath(const Path & root, const Path & prefix) { static thread_local std::random_device generator{}; std::uniform_int_distribution uniform_dist{}; @@ -679,11 +679,7 @@ Path makeTempPath(const Path & root, const std::optional & prefix) reinterpret_cast(entropy), sizeof(entropy) )); - if (prefix) { - return fmt("%s%s-%s", root, *prefix, unique); - } else { - return root + unique; - } + return fmt("%s%s-%s", root, prefix, unique); } Path makeTempSiblingPath(const Path & path) diff --git a/lix/libutil/file-system.hh b/lix/libutil/file-system.hh index f615470fa..85af08fdb 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 std::optional & prefix = "nix", +Path createTempSubdir(const Path & parent, const Path & 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 std::optional & prefix = ".tmp"); +Path makeTempPath(const Path & root, const Path & prefix = ".tmp"); /** * Return temporary path in the same directory as a given path.