Skip to content

Commit b10a636

Browse files
committed
BinaryCacheStoreConfig: Change localNarCache to std::filesystem::path
1 parent b474e8d commit b10a636

3 files changed

Lines changed: 16 additions & 17 deletions

File tree

src/libstore/include/nix/store/binary-cache-store.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ struct BinaryCacheStoreConfig : virtual StoreConfig
3838
const Setting<std::string> secretKeyFiles{
3939
this, "", "secret-keys", "List of comma-separated paths to the secret keys used to sign the binary cache."};
4040

41-
const Setting<Path> localNarCache{
41+
const Setting<std::optional<std::filesystem::path>> localNarCache{
4242
this,
43-
"",
43+
std::nullopt,
4444
"local-nar-cache",
4545
"Path to a local cache of NARs fetched from this binary cache, used by commands such as `nix store cat`."};
4646

src/libstore/include/nix/store/remote-fs-accessor.hh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class RemoteFSAccessor : public SourceAccessor
1515

1616
bool requireValidPath;
1717

18-
Path cacheDir;
18+
std::optional<std::filesystem::path> cacheDir;
1919

2020
std::pair<ref<SourceAccessor>, CanonPath> fetch(const CanonPath & path);
2121

2222
friend struct BinaryCacheStore;
2323

24-
Path makeCacheFile(std::string_view hashPart, const std::string & ext);
24+
std::filesystem::path makeCacheFile(std::string_view hashPart, const std::string & ext);
2525

2626
ref<SourceAccessor> addToCache(std::string_view hashPart, std::string && nar);
2727

@@ -32,8 +32,7 @@ public:
3232
*/
3333
std::shared_ptr<SourceAccessor> accessObject(const StorePath & path);
3434

35-
RemoteFSAccessor(
36-
ref<Store> store, bool requireValidPath = true, const /* FIXME: use std::optional */ Path & cacheDir = "");
35+
RemoteFSAccessor(ref<Store> store, bool requireValidPath = true, std::optional<std::filesystem::path> cacheDir = {});
3736

3837
std::optional<Stat> maybeLstat(const CanonPath & path) override;
3938

src/libstore/remote-fs-accessor.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88

99
namespace 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

2626
ref<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

Comments
 (0)