libutil: add makeTempSiblingPath helper

The prospective callers of this should probably be doing something
smarter or more abstracted to begin with, but this is useful as an
incremental improvement for call sites with existing `makeTempPath`
logic in the face of filename length limits.

Change-Id: I6a6a6964374f47abbf0ec10aa8d945c4e50a43af
This commit is contained in:
Emily
2025-08-18 09:27:31 +00:00
committed by emilazy
parent 3de996f521
commit e2d85579d8
2 changed files with 10 additions and 0 deletions
+5
View File
@@ -693,6 +693,11 @@ Path makeTempPath(const Path & root, const Path & suffix)
return fmt("%1%%2%-%3%-%4%", root, suffix, getpid(), counter.fetch_add(1, std::memory_order_relaxed));
}
Path makeTempSiblingPath(const Path & path)
{
return makeTempPath(fs::path(path).remove_filename());
}
void createSymlink(const Path & target, const Path & link)
{
if (symlink(target.c_str(), link.c_str()))
+5
View File
@@ -318,6 +318,11 @@ Path createTempSubdir(const Path & parent, const Path & prefix = "nix",
*/
Path makeTempPath(const Path & root, const Path & suffix = ".tmp");
/**
* Return temporary path in the same directory as a given path.
*/
Path makeTempSiblingPath(const Path & root);
/**
* Used in various places.
*/