1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

Merge pull request #14383 from obsidiansystems/misc-cleanups

Two misc cleanups
This commit is contained in:
John Ericson 2025-10-27 22:16:37 +00:00 committed by GitHub
commit 1d3f0ca22e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 36 additions and 31 deletions

View file

@ -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( void queryRealisationUncached(
const DrvOutput & drvOutput, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept override const DrvOutput & drvOutput, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept override
{ {

View file

@ -78,7 +78,6 @@ struct LocalFSStore : virtual Store, virtual GcStore, virtual LogStore
LocalFSStore(const Config & params); LocalFSStore(const Config & params);
void narFromPath(const StorePath & path, Sink & sink) override;
ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override; ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override;
std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath = true) override; std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath = true) override;

View file

@ -609,7 +609,7 @@ public:
/** /**
* Write a NAR dump of a store path. * 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 * For each path, if it's a derivation, build it. Building a

View file

@ -68,7 +68,7 @@ struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore
void narFromPath(const StorePath & path, Sink & sink) override void narFromPath(const StorePath & path, Sink & sink) override
{ {
LocalFSStore::narFromPath(path, sink); Store::narFromPath(path, sink);
} }
/** /**

View file

@ -112,13 +112,6 @@ std::shared_ptr<SourceAccessor> LocalFSStore::getFSAccessor(const StorePath & pa
return std::make_shared<PosixSourceAccessor>(std::move(absPath)); 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"; const std::string LocalFSStore::drvsLogDir = "drvs";
std::optional<std::string> LocalFSStore::getBuildLogExact(const StorePath & path) std::optional<std::string> LocalFSStore::getBuildLogExact(const StorePath & path)

View file

@ -226,7 +226,7 @@ void RestrictedStore::narFromPath(const StorePath & path, Sink & sink)
{ {
if (!goal.isAllowed(path)) if (!goal.isAllowed(path))
throw InvalidPath("cannot dump unknown path '%s' in recursive Nix", printStorePath(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) void RestrictedStore::ensurePath(const StorePath & path)

View file

@ -143,7 +143,7 @@ struct MountedSSHStore : virtual SSHStore, virtual LocalFSStore
void narFromPath(const StorePath & path, Sink & sink) override void narFromPath(const StorePath & path, Sink & sink) override
{ {
return LocalFSStore::narFromPath(path, sink); return Store::narFromPath(path, sink);
} }
ref<SourceAccessor> getFSAccessor(bool requireValidPath) override ref<SourceAccessor> getFSAccessor(bool requireValidPath) override

View file

@ -300,6 +300,13 @@ ValidPathInfo Store::addToStoreSlow(
return info; 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() StringSet Store::Config::getDefaultSystemFeatures()
{ {
auto res = settings.systemFeatures.get(); auto res = settings.systemFeatures.get();

View file

@ -17,6 +17,12 @@ private:
std::shared_ptr<T> p; std::shared_ptr<T> p;
void assertNonNull()
{
if (!p)
throw std::invalid_argument("null pointer cast to ref");
}
public: public:
using element_type = T; using element_type = T;
@ -24,15 +30,19 @@ public:
explicit ref(const std::shared_ptr<T> & p) explicit ref(const std::shared_ptr<T> & p)
: p(p) : p(p)
{ {
if (!p) assertNonNull();
throw std::invalid_argument("null pointer cast to ref"); }
explicit ref(std::shared_ptr<T> && p)
: p(std::move(p))
{
assertNonNull();
} }
explicit ref(T * p) explicit ref(T * p)
: p(p) : p(p)
{ {
if (!p) assertNonNull();
throw std::invalid_argument("null pointer cast to ref");
} }
T * operator->() const T * operator->() const
@ -45,14 +55,22 @@ public:
return *p; return *p;
} }
operator std::shared_ptr<T>() const std::shared_ptr<T> get_ptr() const &
{ {
return p; 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> template<typename T2>