Skip to content

Commit dd716dc

Browse files
committed
Create default Store::narFromPath implementation in terms of getFSAccessor
This is a good default (the methods that allow for an arbitrary choice of source accessor are generally preferable both to implement and to use). And it also pays its way by allowing us to delete *both* the `DummyStore` and `LocalStore` implementations.
1 parent c5515bb commit dd716dc

File tree

8 files changed

+11
-24
lines changed

8 files changed

+11
-24
lines changed

src/libstore/dummy-store.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,6 @@ struct DummyStoreImpl : DummyStore
258258
});
259259
}
260260

261-
void narFromPath(const StorePath & path, Sink & sink) override
262-
{
263-
bool visited = contents.cvisit(path, [&](const auto & kv) {
264-
const auto & [info, accessor] = kv.second;
265-
SourcePath sourcePath(accessor);
266-
dumpPath(sourcePath, sink, FileSerialisationMethod::NixArchive);
267-
});
268-
269-
if (!visited)
270-
throw Error("path '%s' is not valid", printStorePath(path));
271-
}
272-
273261
void queryRealisationUncached(
274262
const DrvOutput & drvOutput, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept override
275263
{

src/libstore/include/nix/store/local-fs-store.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ struct LocalFSStore : virtual Store, virtual GcStore, virtual LogStore
7878

7979
LocalFSStore(const Config & params);
8080

81-
void narFromPath(const StorePath & path, Sink & sink) override;
8281
ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override;
8382
std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath = true) override;
8483

src/libstore/include/nix/store/store-api.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ public:
609609
/**
610610
* Write a NAR dump of a store path.
611611
*/
612-
virtual void narFromPath(const StorePath & path, Sink & sink) = 0;
612+
virtual void narFromPath(const StorePath & path, Sink & sink);
613613

614614
/**
615615
* For each path, if it's a derivation, build it. Building a

src/libstore/include/nix/store/uds-remote-store.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore
6868

6969
void narFromPath(const StorePath & path, Sink & sink) override
7070
{
71-
LocalFSStore::narFromPath(path, sink);
71+
Store::narFromPath(path, sink);
7272
}
7373

7474
/**

src/libstore/local-fs-store.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,6 @@ std::shared_ptr<SourceAccessor> LocalFSStore::getFSAccessor(const StorePath & pa
112112
return std::make_shared<PosixSourceAccessor>(std::move(absPath));
113113
}
114114

115-
void LocalFSStore::narFromPath(const StorePath & path, Sink & sink)
116-
{
117-
if (!isValidPath(path))
118-
throw Error("path '%s' is not valid", printStorePath(path));
119-
dumpPath(getRealStoreDir() + std::string(printStorePath(path), storeDir.size()), sink);
120-
}
121-
122115
const std::string LocalFSStore::drvsLogDir = "drvs";
123116

124117
std::optional<std::string> LocalFSStore::getBuildLogExact(const StorePath & path)

src/libstore/restricted-store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void RestrictedStore::narFromPath(const StorePath & path, Sink & sink)
226226
{
227227
if (!goal.isAllowed(path))
228228
throw InvalidPath("cannot dump unknown path '%s' in recursive Nix", printStorePath(path));
229-
LocalFSStore::narFromPath(path, sink);
229+
Store::narFromPath(path, sink);
230230
}
231231

232232
void RestrictedStore::ensurePath(const StorePath & path)

src/libstore/ssh-store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ struct MountedSSHStore : virtual SSHStore, virtual LocalFSStore
143143

144144
void narFromPath(const StorePath & path, Sink & sink) override
145145
{
146-
return LocalFSStore::narFromPath(path, sink);
146+
return Store::narFromPath(path, sink);
147147
}
148148

149149
ref<SourceAccessor> getFSAccessor(bool requireValidPath) override

src/libstore/store-api.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ ValidPathInfo Store::addToStoreSlow(
300300
return info;
301301
}
302302

303+
void Store::narFromPath(const StorePath & path, Sink & sink)
304+
{
305+
auto accessor = requireStoreObjectAccessor(path);
306+
SourcePath sourcePath{accessor};
307+
dumpPath(sourcePath, sink, FileSerialisationMethod::NixArchive);
308+
}
309+
303310
StringSet Store::Config::getDefaultSystemFeatures()
304311
{
305312
auto res = settings.systemFeatures.get();

0 commit comments

Comments
 (0)