Skip to content

Commit 2af5792

Browse files
committed
Inline RemoteFSAccessor::addToCache
It was not pulling its weight. (Only used once, optional paths are confusing, we already have an `if` / branch fit-for-purpose.)
1 parent e251ffd commit 2af5792

2 files changed

Lines changed: 28 additions & 35 deletions

File tree

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ class RemoteFSAccessor : public SourceAccessor
3333

3434
std::filesystem::path makeCacheFile(const Hash & narHash, const std::string & ext);
3535

36-
ref<SourceAccessor>
37-
addToCache(const std::filesystem::path & cacheFile, const std::filesystem::path & listingFile, std::string && nar);
38-
3936
public:
4037

4138
/**

src/libstore/remote-fs-accessor.cc

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,6 @@ std::filesystem::path RemoteFSAccessor::makeCacheFile(const Hash & narHash, cons
2727
return res;
2828
}
2929

30-
ref<SourceAccessor> RemoteFSAccessor::addToCache(
31-
const std::filesystem::path & cacheFile, const std::filesystem::path & listingFile, std::string && nar)
32-
{
33-
if (!cacheFile.empty()) {
34-
try {
35-
/* FIXME: do this asynchronously. */
36-
writeFile(cacheFile, nar);
37-
} catch (...) {
38-
ignoreExceptionExceptInterrupt();
39-
}
40-
}
41-
42-
auto narAccessor = makeNarAccessor(std::move(nar));
43-
44-
if (!listingFile.empty()) {
45-
try {
46-
nlohmann::json j = listNarDeep(*narAccessor, CanonPath::root);
47-
writeFile(listingFile, j.dump());
48-
} catch (...) {
49-
ignoreExceptionExceptInterrupt();
50-
}
51-
}
52-
53-
return narAccessor;
54-
}
55-
5630
std::pair<ref<SourceAccessor>, CanonPath> RemoteFSAccessor::fetch(const CanonPath & path)
5731
{
5832
auto [storePath, restPath] = store->toStorePath(store->storeDir + path.abs());
@@ -76,11 +50,15 @@ std::shared_ptr<SourceAccessor> RemoteFSAccessor::accessObject(const StorePath &
7650
return accessor;
7751
};
7852

79-
std::filesystem::path cacheFile, listingFile;
53+
auto getNar = [&]() {
54+
StringSink sink;
55+
store->narFromPath(storePath, sink);
56+
return std::move(sink.s);
57+
};
8058

8159
if (cacheDir) {
82-
cacheFile = makeCacheFile(info->narHash, "nar");
83-
listingFile = makeCacheFile(info->narHash, "ls");
60+
auto cacheFile = makeCacheFile(info->narHash, "nar");
61+
auto listingFile = makeCacheFile(info->narHash, "ls");
8462

8563
if (nix::pathExists(cacheFile)) {
8664
try {
@@ -95,11 +73,29 @@ std::shared_ptr<SourceAccessor> RemoteFSAccessor::accessObject(const StorePath &
9573
} catch (SystemError &) {
9674
}
9775
}
76+
77+
auto nar = getNar();
78+
79+
try {
80+
/* FIXME: do this asynchronously. */
81+
writeFile(cacheFile, nar);
82+
} catch (...) {
83+
ignoreExceptionExceptInterrupt();
84+
}
85+
86+
auto narAccessor = makeNarAccessor(std::move(nar));
87+
88+
try {
89+
nlohmann::json j = listNarDeep(*narAccessor, CanonPath::root);
90+
writeFile(listingFile, j.dump());
91+
} catch (...) {
92+
ignoreExceptionExceptInterrupt();
93+
}
94+
95+
return cacheAccessor(narAccessor);
9896
}
9997

100-
StringSink sink;
101-
store->narFromPath(storePath, sink);
102-
return cacheAccessor(addToCache(cacheFile, listingFile, std::move(sink.s)));
98+
return cacheAccessor(makeNarAccessor(getNar()));
10399
}
104100

105101
std::optional<SourceAccessor::Stat> RemoteFSAccessor::maybeLstat(const CanonPath & path)

0 commit comments

Comments
 (0)