From 3cc07ede73215860c42779e1527ffc3a88c65d7f Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 17 Dec 2025 17:33:37 -0500 Subject: [PATCH] `LocalBinaryCacheStore::upsertFile` support slash in path While working on #12464, I realized this method was not correct in this case. With the current binary cache format, it is harmless, since we don't create arbitrary directories, but with my change, we started to. Regardless of whether we need it or not, I think it is better if the function just does the right thing. --- src/libstore/local-binary-cache-store.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc index 63730a01bd7..b89db508c33 100644 --- a/src/libstore/local-binary-cache-store.cc +++ b/src/libstore/local-binary-cache-store.cc @@ -56,9 +56,11 @@ struct LocalBinaryCacheStore : virtual BinaryCacheStore void upsertFile( const std::string & path, RestartableSource & source, const std::string & mimeType, uint64_t sizeHint) override { - auto path2 = config->binaryCacheDir + "/" + path; + auto path2 = std::filesystem::path{config->binaryCacheDir} / path; static std::atomic counter{0}; - Path tmp = fmt("%s.tmp.%d.%d", path2, getpid(), ++counter); + createDirs(path2.parent_path()); + auto tmp = path2; + tmp += fmt(".tmp.%d.%d", getpid(), ++counter); AutoDelete del(tmp, false); writeFile(tmp, source); std::filesystem::rename(tmp, path2);