From 28bcc7fb2416ac5c9b0f0b24172416560b03797b Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Thu, 21 Aug 2025 14:36:10 +0000 Subject: [PATCH] =?UTF-8?q?Revert=20"libutil:=20use=20OS=E2=80=90provided?= =?UTF-8?q?=20entropy=20for=20temporary=20filenames"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Icdbb89bbf031581250fbda3c9ab9095e7af10ec1 --- lix/libutil/file-system.cc | 13 ++++--------- lix/libutil/file-system.hh | 8 ++++---- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lix/libutil/file-system.cc b/lix/libutil/file-system.cc index 6a62e0dd1..4464fccf5 100644 --- a/lix/libutil/file-system.cc +++ b/lix/libutil/file-system.cc @@ -686,16 +686,11 @@ Path createTempSubdir(const Path & parent, const Path & prefix, } } -Path makeTempPath(const Path & root, const Path & prefix) +Path makeTempPath(const Path & root, const Path & suffix) { - static thread_local std::random_device generator{}; - std::uniform_int_distribution uniform_dist{}; - const uint64_t entropy[2] = {uniform_dist(generator), uniform_dist(generator)}; - const std::string unique = base32Encode(std::string_view( - reinterpret_cast(entropy), - sizeof(entropy) - )); - return fmt("%s%s-%s", root, prefix, unique); + // start the counter at a random value to minimize issues with preexisting temp paths + static std::atomic_uint_fast32_t counter(std::random_device{}()); + return fmt("%1%%2%-%3%-%4%", root, suffix, getpid(), counter.fetch_add(1, std::memory_order_relaxed)); } Path makeTempSiblingPath(const Path & path) diff --git a/lix/libutil/file-system.hh b/lix/libutil/file-system.hh index fb8b93a80..cdcb61a65 100644 --- a/lix/libutil/file-system.hh +++ b/lix/libutil/file-system.hh @@ -311,12 +311,12 @@ Path createTempSubdir(const Path & parent, const Path & prefix = "nix", bool includePid = true, bool useGlobalCounter = true, mode_t mode = 0755); /** - * Return temporary path constructed by appending to a root path. + * Return temporary path constructed by appending a suffix to a root path. * - * The constructed path looks like `-`. To create a - * path nested in a directory, provide a root ending with `/`. + * The constructed path looks like `--`. To create a + * path nested in a directory, provide a suffix starting with `/`. */ -Path makeTempPath(const Path & root, const Path & prefix = ".tmp"); +Path makeTempPath(const Path & root, const Path & suffix = ".tmp"); /** * Return temporary path in the same directory as a given path.