88
99namespace nix {
1010
11- RemoteFSAccessor::RemoteFSAccessor (ref<Store> store, bool requireValidPath, const Path & cacheDir )
11+ RemoteFSAccessor::RemoteFSAccessor (ref<Store> store, bool requireValidPath, std::optional<std::filesystem::path> cacheDir_ )
1212 : store(store)
1313 , requireValidPath(requireValidPath)
14- , cacheDir(cacheDir )
14+ , cacheDir(std::move(cacheDir_) )
1515{
16- if (cacheDir != " " )
17- createDirs (cacheDir);
16+ if (cacheDir)
17+ createDirs (* cacheDir);
1818}
1919
20- Path RemoteFSAccessor::makeCacheFile (std::string_view hashPart, const std::string & ext)
20+ std::filesystem::path RemoteFSAccessor::makeCacheFile (std::string_view hashPart, const std::string & ext)
2121{
22- assert (cacheDir != " " );
23- return fmt ( " %s/%s.%s " , cacheDir, hashPart, ext) ;
22+ assert (cacheDir);
23+ return (*cacheDir / hashPart) + " . " + ext;
2424}
2525
2626ref<SourceAccessor> RemoteFSAccessor::addToCache (std::string_view hashPart, std::string && nar)
2727{
28- if (cacheDir != " " ) {
28+ if (cacheDir) {
2929 try {
3030 /* FIXME: do this asynchronously. */
3131 writeFile (makeCacheFile (hashPart, " nar" ), nar);
@@ -37,7 +37,7 @@ ref<SourceAccessor> RemoteFSAccessor::addToCache(std::string_view hashPart, std:
3737 auto narAccessor = makeNarAccessor (std::move (nar));
3838 nars.emplace (hashPart, narAccessor);
3939
40- if (cacheDir != " " ) {
40+ if (cacheDir) {
4141 try {
4242 nlohmann::json j = listNarDeep (*narAccessor, CanonPath::root);
4343 writeFile (makeCacheFile (hashPart, " ls" ), j.dump ());
@@ -64,9 +64,9 @@ std::shared_ptr<SourceAccessor> RemoteFSAccessor::accessObject(const StorePath &
6464 return i->second ;
6565
6666 std::string listing;
67- Path cacheFile;
67+ std::filesystem::path cacheFile;
6868
69- if (cacheDir != " " && nix::pathExists (cacheFile = makeCacheFile (storePath.hashPart (), " nar" ))) {
69+ if (cacheDir && nix::pathExists (cacheFile = makeCacheFile (storePath.hashPart (), " nar" ))) {
7070
7171 try {
7272 listing = nix::readFile (makeCacheFile (storePath.hashPart (), " ls" ));
0 commit comments