88
99namespace nix {
1010
11- RemoteFSAccessor::RemoteFSAccessor (ref<Store> store, bool requireValidPath, const Path & cacheDir)
11+ RemoteFSAccessor::RemoteFSAccessor (
12+ ref<Store> store, bool requireValidPath, std::optional<std::filesystem::path> cacheDir_)
1213 : store(store)
1314 , requireValidPath(requireValidPath)
14- , cacheDir(cacheDir )
15+ , cacheDir(std::move(cacheDir_) )
1516{
16- if (cacheDir != " " )
17- createDirs (cacheDir);
17+ if (cacheDir)
18+ createDirs (* cacheDir);
1819}
1920
20- Path RemoteFSAccessor::makeCacheFile (std::string_view hashPart, const std::string & ext)
21+ std::filesystem::path RemoteFSAccessor::makeCacheFile (std::string_view hashPart, const std::string & ext)
2122{
22- assert (cacheDir != " " );
23- return fmt ( " %s/%s.%s " , cacheDir, hashPart, ext) ;
23+ assert (cacheDir);
24+ return (*cacheDir / hashPart) + " . " + ext;
2425}
2526
2627ref<SourceAccessor> RemoteFSAccessor::addToCache (std::string_view hashPart, std::string && nar)
2728{
28- if (cacheDir != " " ) {
29+ if (cacheDir) {
2930 try {
3031 /* FIXME: do this asynchronously. */
3132 writeFile (makeCacheFile (hashPart, " nar" ), nar);
@@ -37,7 +38,7 @@ ref<SourceAccessor> RemoteFSAccessor::addToCache(std::string_view hashPart, std:
3738 auto narAccessor = makeNarAccessor (std::move (nar));
3839 nars.emplace (hashPart, narAccessor);
3940
40- if (cacheDir != " " ) {
41+ if (cacheDir) {
4142 try {
4243 nlohmann::json j = listNarDeep (*narAccessor, CanonPath::root);
4344 writeFile (makeCacheFile (hashPart, " ls" ), j.dump ());
@@ -64,9 +65,9 @@ std::shared_ptr<SourceAccessor> RemoteFSAccessor::accessObject(const StorePath &
6465 return i->second ;
6566
6667 std::string listing;
67- Path cacheFile;
68+ std::filesystem::path cacheFile;
6869
69- if (cacheDir != " " && nix::pathExists (cacheFile = makeCacheFile (storePath.hashPart (), " nar" ))) {
70+ if (cacheDir && nix::pathExists (cacheFile = makeCacheFile (storePath.hashPart (), " nar" ))) {
7071
7172 try {
7273 listing = nix::readFile (makeCacheFile (storePath.hashPart (), " ls" ));
0 commit comments