1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-20 11:11:03 -04:00
nix/src/libstore/local-fs-store.cc
Eelco Dolstra 1c5f73f529 Add Store::dumpPath() method
This allows applying nix-store --verify-path to binary cache stores:

  NIX_REMOTE=https://cache.nixos.org nix-store --verify-path /nix/store/s5c7...
2016-03-21 17:55:57 +01:00

78 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "archive.hh"
#include "fs-accessor.hh"
#include "store-api.hh"
namespace nix {
struct LocalStoreAccessor : public FSAccessor
{
ref<Store> store;
LocalStoreAccessor(ref<Store> store) : store(store) { }
void assertStore(const Path & path)
{
Path storePath = toStorePath(path);
if (!store->isValidPath(storePath))
throw Error(format("path %1% is not a valid store path") % storePath);
}
FSAccessor::Stat stat(const Path & path) override
{
assertStore(path);
struct stat st;
if (lstat(path.c_str(), &st)) {
if (errno == ENOENT) return {Type::tMissing, 0, false};
throw SysError(format("getting status of %1%") % path);
}
if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode))
throw Error(format("file %1% has unsupported type") % path);
return {
S_ISREG(st.st_mode) ? Type::tRegular :
S_ISLNK(st.st_mode) ? Type::tSymlink :
Type::tDirectory,
S_ISREG(st.st_mode) ? (uint64_t) st.st_size : 0,
S_ISREG(st.st_mode) && st.st_mode & S_IXUSR};
}
StringSet readDirectory(const Path & path) override
{
assertStore(path);
auto entries = nix::readDirectory(path);
StringSet res;
for (auto & entry : entries)
res.insert(entry.name);
return res;
}
std::string readFile(const Path & path) override
{
assertStore(path);
return nix::readFile(path);
}
std::string readLink(const Path & path) override
{
assertStore(path);
return nix::readLink(path);
}
};
ref<FSAccessor> LocalFSStore::getFSAccessor()
{
return make_ref<LocalStoreAccessor>(ref<Store>(shared_from_this()));
}
void LocalFSStore::dumpPath(const Path & path, Sink & sink)
{
nix::dumpPath(path, sink);
}
}