Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/libstore/dummy-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,6 @@ struct DummyStoreImpl : DummyStore
});
}

void narFromPath(const StorePath & path, Sink & sink) override
{
bool visited = contents.cvisit(path, [&](const auto & kv) {
const auto & [info, accessor] = kv.second;
SourcePath sourcePath(accessor);
dumpPath(sourcePath, sink, FileSerialisationMethod::NixArchive);
});

if (!visited)
throw Error("path '%s' is not valid", printStorePath(path));
}

void queryRealisationUncached(
const DrvOutput & drvOutput, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept override
{
Expand Down
1 change: 0 additions & 1 deletion src/libstore/include/nix/store/local-fs-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ struct LocalFSStore : virtual Store, virtual GcStore, virtual LogStore

LocalFSStore(const Config & params);

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

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/include/nix/store/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ public:
/**
* Write a NAR dump of a store path.
*/
virtual void narFromPath(const StorePath & path, Sink & sink) = 0;
virtual void narFromPath(const StorePath & path, Sink & sink);

/**
* For each path, if it's a derivation, build it. Building a
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/include/nix/store/uds-remote-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore

void narFromPath(const StorePath & path, Sink & sink) override
{
LocalFSStore::narFromPath(path, sink);
Store::narFromPath(path, sink);
}

/**
Expand Down
7 changes: 0 additions & 7 deletions src/libstore/local-fs-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ std::shared_ptr<SourceAccessor> LocalFSStore::getFSAccessor(const StorePath & pa
return std::make_shared<PosixSourceAccessor>(std::move(absPath));
}

void LocalFSStore::narFromPath(const StorePath & path, Sink & sink)
{
if (!isValidPath(path))
throw Error("path '%s' is not valid", printStorePath(path));
dumpPath(getRealStoreDir() + std::string(printStorePath(path), storeDir.size()), sink);
}

const std::string LocalFSStore::drvsLogDir = "drvs";

std::optional<std::string> LocalFSStore::getBuildLogExact(const StorePath & path)
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/restricted-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void RestrictedStore::narFromPath(const StorePath & path, Sink & sink)
{
if (!goal.isAllowed(path))
throw InvalidPath("cannot dump unknown path '%s' in recursive Nix", printStorePath(path));
LocalFSStore::narFromPath(path, sink);
Store::narFromPath(path, sink);
}

void RestrictedStore::ensurePath(const StorePath & path)
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ struct MountedSSHStore : virtual SSHStore, virtual LocalFSStore

void narFromPath(const StorePath & path, Sink & sink) override
{
return LocalFSStore::narFromPath(path, sink);
return Store::narFromPath(path, sink);
}

ref<SourceAccessor> getFSAccessor(bool requireValidPath) override
Expand Down
7 changes: 7 additions & 0 deletions src/libstore/store-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ ValidPathInfo Store::addToStoreSlow(
return info;
}

void Store::narFromPath(const StorePath & path, Sink & sink)
{
auto accessor = requireStoreObjectAccessor(path);
SourcePath sourcePath{accessor};
dumpPath(sourcePath, sink, FileSerialisationMethod::NixArchive);
}

StringSet Store::Config::getDefaultSystemFeatures()
{
auto res = settings.systemFeatures.get();
Expand Down
32 changes: 25 additions & 7 deletions src/libutil/include/nix/util/ref.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,32 @@ private:

std::shared_ptr<T> p;

void assertNonNull()
{
if (!p)
throw std::invalid_argument("null pointer cast to ref");
}

public:

using element_type = T;

explicit ref(const std::shared_ptr<T> & p)
: p(p)
{
if (!p)
throw std::invalid_argument("null pointer cast to ref");
assertNonNull();
}

explicit ref(std::shared_ptr<T> && p)
: p(std::move(p))
{
assertNonNull();
}

explicit ref(T * p)
: p(p)
{
if (!p)
throw std::invalid_argument("null pointer cast to ref");
assertNonNull();
}

T * operator->() const
Expand All @@ -45,14 +55,22 @@ public:
return *p;
}

operator std::shared_ptr<T>() const
std::shared_ptr<T> get_ptr() const &
{
return p;
}

std::shared_ptr<T> get_ptr() const
std::shared_ptr<T> get_ptr() &&
{
return p;
return std::move(p);
}

/**
* Convenience to avoid explicit `get_ptr()` call in some cases.
*/
operator std::shared_ptr<T>(this auto && self)
{
return std::forward<decltype(self)>(self).get_ptr();
}

template<typename T2>
Expand Down
Loading