Revert "libutil: use OS‐provided entropy for temporary filenames"

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
This commit is contained in:
Raito Bezarius
2025-08-21 14:37:46 +00:00
parent 7c03f42759
commit 28bcc7fb24
2 changed files with 8 additions and 13 deletions
+4 -9
View File
@@ -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<uint64_t> uniform_dist{};
const uint64_t entropy[2] = {uniform_dist(generator), uniform_dist(generator)};
const std::string unique = base32Encode(std::string_view(
reinterpret_cast<const char *>(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)
+4 -4
View File
@@ -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 `<root><prefix>-<unique>`. To create a
* path nested in a directory, provide a root ending with `/`.
* The constructed path looks like `<root><suffix>-<pid>-<unique>`. 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.