From 1cc3989c8ed42461bb29f82c4b981b0c604b5308 Mon Sep 17 00:00:00 2001 From: Emily Date: Mon, 4 Aug 2025 15:10:28 +0100 Subject: [PATCH] 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: I6a6a69644292f5bbf984a1df90192e06c6022b53 --- lix/libutil/file-system.cc | 5 +++++ lix/libutil/file-system.hh | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lix/libutil/file-system.cc b/lix/libutil/file-system.cc index f62a54b5d..806190316 100644 --- a/lix/libutil/file-system.cc +++ b/lix/libutil/file-system.cc @@ -689,6 +689,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())) diff --git a/lix/libutil/file-system.hh b/lix/libutil/file-system.hh index a1295c613..16f4d0518 100644 --- a/lix/libutil/file-system.hh +++ b/lix/libutil/file-system.hh @@ -312,6 +312,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 & path); + /** * Used in various places. */