Skip to content

Commit 517f53f

Browse files
committed
BinaryCacheStoreConfig: Change localNarCache to std::filesystem::path
1 parent 33f52c3 commit 517f53f

3 files changed

Lines changed: 17 additions & 16 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 & 3 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

@@ -33,7 +33,7 @@ public:
3333
std::shared_ptr<SourceAccessor> accessObject(const StorePath & path);
3434

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

3838
std::optional<Stat> maybeLstat(const CanonPath & path) override;
3939

src/libstore/remote-fs-accessor.cc

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

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

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

Comments
 (0)