mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 14:06:16 +02:00
Merge pull request #9317 from tfc/libstore-improvementswq
Libstore improvements
This commit is contained in:
commit
c14ba93290
6 changed files with 29 additions and 21 deletions
|
@ -60,12 +60,22 @@ struct NarAccessor : public SourceAccessor
|
||||||
|
|
||||||
void createDirectory(const Path & path) override
|
void createDirectory(const Path & path) override
|
||||||
{
|
{
|
||||||
createMember(path, {Type::tDirectory, false, 0, 0});
|
createMember(path, NarMember{ .stat = {
|
||||||
|
.type = Type::tDirectory,
|
||||||
|
.fileSize = 0,
|
||||||
|
.isExecutable = false,
|
||||||
|
.narOffset = 0
|
||||||
|
} });
|
||||||
}
|
}
|
||||||
|
|
||||||
void createRegularFile(const Path & path) override
|
void createRegularFile(const Path & path) override
|
||||||
{
|
{
|
||||||
createMember(path, {Type::tRegular, false, 0, 0});
|
createMember(path, NarMember{ .stat = {
|
||||||
|
.type = Type::tRegular,
|
||||||
|
.fileSize = 0,
|
||||||
|
.isExecutable = false,
|
||||||
|
.narOffset = 0
|
||||||
|
} });
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeRegularFile() override
|
void closeRegularFile() override
|
||||||
|
@ -78,9 +88,8 @@ struct NarAccessor : public SourceAccessor
|
||||||
|
|
||||||
void preallocateContents(uint64_t size) override
|
void preallocateContents(uint64_t size) override
|
||||||
{
|
{
|
||||||
assert(size <= std::numeric_limits<uint64_t>::max());
|
|
||||||
auto & st = parents.top()->stat;
|
auto & st = parents.top()->stat;
|
||||||
st.fileSize = (uint64_t) size;
|
st.fileSize = size;
|
||||||
st.narOffset = pos;
|
st.narOffset = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,9 +137,8 @@ struct NarAccessor : public SourceAccessor
|
||||||
|
|
||||||
if (type == "directory") {
|
if (type == "directory") {
|
||||||
member.stat = {.type = Type::tDirectory};
|
member.stat = {.type = Type::tDirectory};
|
||||||
for (auto i = v["entries"].begin(); i != v["entries"].end(); ++i) {
|
for (const auto &[name, function] : v["entries"].items()) {
|
||||||
std::string name = i.key();
|
recurse(member.children[name], function);
|
||||||
recurse(member.children[name], i.value());
|
|
||||||
}
|
}
|
||||||
} else if (type == "regular") {
|
} else if (type == "regular") {
|
||||||
member.stat = {
|
member.stat = {
|
||||||
|
@ -153,7 +161,7 @@ struct NarAccessor : public SourceAccessor
|
||||||
{
|
{
|
||||||
NarMember * current = &root;
|
NarMember * current = &root;
|
||||||
|
|
||||||
for (auto & i : path) {
|
for (const auto & i : path) {
|
||||||
if (current->stat.type != Type::tDirectory) return nullptr;
|
if (current->stat.type != Type::tDirectory) return nullptr;
|
||||||
auto child = current->children.find(std::string(i));
|
auto child = current->children.find(std::string(i));
|
||||||
if (child == current->children.end()) return nullptr;
|
if (child == current->children.end()) return nullptr;
|
||||||
|
@ -186,7 +194,7 @@ struct NarAccessor : public SourceAccessor
|
||||||
throw Error("path '%1%' inside NAR file is not a directory", path);
|
throw Error("path '%1%' inside NAR file is not a directory", path);
|
||||||
|
|
||||||
DirEntries res;
|
DirEntries res;
|
||||||
for (auto & child : i.children)
|
for (const auto & child : i.children)
|
||||||
res.insert_or_assign(child.first, std::nullopt);
|
res.insert_or_assign(child.first, std::nullopt);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -251,7 +259,7 @@ json listNar(ref<SourceAccessor> accessor, const CanonPath & path, bool recurse)
|
||||||
{
|
{
|
||||||
obj["entries"] = json::object();
|
obj["entries"] = json::object();
|
||||||
json &res2 = obj["entries"];
|
json &res2 = obj["entries"];
|
||||||
for (auto & [name, type] : accessor->readDirectory(path)) {
|
for (const auto & [name, type] : accessor->readDirectory(path)) {
|
||||||
if (recurse) {
|
if (recurse) {
|
||||||
res2[name] = listNar(accessor, path + name, true);
|
res2[name] = listNar(accessor, path + name, true);
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -25,7 +25,7 @@ ref<SourceAccessor> makeNarAccessor(Source & source);
|
||||||
* readFile() method of the accessor to get the contents of files
|
* readFile() method of the accessor to get the contents of files
|
||||||
* inside the NAR.
|
* inside the NAR.
|
||||||
*/
|
*/
|
||||||
typedef std::function<std::string(uint64_t, uint64_t)> GetNarBytes;
|
using GetNarBytes = std::function<std::string(uint64_t, uint64_t)>;
|
||||||
|
|
||||||
ref<SourceAccessor> makeLazyNarAccessor(
|
ref<SourceAccessor> makeLazyNarAccessor(
|
||||||
const std::string & listing,
|
const std::string & listing,
|
||||||
|
|
|
@ -38,12 +38,12 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &
|
||||||
while (pos < s.size()) {
|
while (pos < s.size()) {
|
||||||
|
|
||||||
size_t colon = s.find(':', pos);
|
size_t colon = s.find(':', pos);
|
||||||
if (colon == std::string::npos) throw corrupt("expecting ':'");
|
if (colon == s.npos) throw corrupt("expecting ':'");
|
||||||
|
|
||||||
std::string name(s, pos, colon - pos);
|
std::string name(s, pos, colon - pos);
|
||||||
|
|
||||||
size_t eol = s.find('\n', colon + 2);
|
size_t eol = s.find('\n', colon + 2);
|
||||||
if (eol == std::string::npos) throw corrupt("expecting '\\n'");
|
if (eol == s.npos) throw corrupt("expecting '\\n'");
|
||||||
|
|
||||||
std::string value(s, colon + 2, eol - colon - 2);
|
std::string value(s, colon + 2, eol - colon - 2);
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,10 @@ struct NarInfo : ValidPathInfo
|
||||||
uint64_t fileSize = 0;
|
uint64_t fileSize = 0;
|
||||||
|
|
||||||
NarInfo() = delete;
|
NarInfo() = delete;
|
||||||
NarInfo(const Store & store, std::string && name, ContentAddressWithReferences && ca, Hash narHash)
|
NarInfo(const Store & store, std::string name, ContentAddressWithReferences ca, Hash narHash)
|
||||||
: ValidPathInfo(store, std::move(name), std::move(ca), narHash)
|
: ValidPathInfo(store, std::move(name), std::move(ca), narHash)
|
||||||
{ }
|
{ }
|
||||||
NarInfo(StorePath && path, Hash narHash) : ValidPathInfo(std::move(path), narHash) { }
|
NarInfo(StorePath path, Hash narHash) : ValidPathInfo(std::move(path), narHash) { }
|
||||||
NarInfo(const ValidPathInfo & info) : ValidPathInfo(info) { }
|
NarInfo(const ValidPathInfo & info) : ValidPathInfo(info) { }
|
||||||
NarInfo(const Store & store, const std::string & s, const std::string & whence);
|
NarInfo(const Store & store, const std::string & s, const std::string & whence);
|
||||||
|
|
||||||
|
|
|
@ -31,14 +31,14 @@ std::optional<TrustedFlag> WorkerProto::Serialise<std::optional<TrustedFlag>>::r
|
||||||
void WorkerProto::Serialise<std::optional<TrustedFlag>>::write(const Store & store, WorkerProto::WriteConn conn, const std::optional<TrustedFlag> & optTrusted)
|
void WorkerProto::Serialise<std::optional<TrustedFlag>>::write(const Store & store, WorkerProto::WriteConn conn, const std::optional<TrustedFlag> & optTrusted)
|
||||||
{
|
{
|
||||||
if (!optTrusted)
|
if (!optTrusted)
|
||||||
conn.to << (uint8_t)0;
|
conn.to << uint8_t{0};
|
||||||
else {
|
else {
|
||||||
switch (*optTrusted) {
|
switch (*optTrusted) {
|
||||||
case Trusted:
|
case Trusted:
|
||||||
conn.to << (uint8_t)1;
|
conn.to << uint8_t{1};
|
||||||
break;
|
break;
|
||||||
case NotTrusted:
|
case NotTrusted:
|
||||||
conn.to << (uint8_t)2;
|
conn.to << uint8_t{2};
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
|
@ -101,7 +101,7 @@ void WorkerProto::Serialise<KeyedBuildResult>::write(const Store & store, Worker
|
||||||
BuildResult WorkerProto::Serialise<BuildResult>::read(const Store & store, WorkerProto::ReadConn conn)
|
BuildResult WorkerProto::Serialise<BuildResult>::read(const Store & store, WorkerProto::ReadConn conn)
|
||||||
{
|
{
|
||||||
BuildResult res;
|
BuildResult res;
|
||||||
res.status = (BuildResult::Status) readInt(conn.from);
|
res.status = static_cast<BuildResult::Status>(readInt(conn.from));
|
||||||
conn.from >> res.errorMsg;
|
conn.from >> res.errorMsg;
|
||||||
if (GET_PROTOCOL_MINOR(conn.version) >= 29) {
|
if (GET_PROTOCOL_MINOR(conn.version) >= 29) {
|
||||||
conn.from
|
conn.from
|
||||||
|
|
|
@ -171,7 +171,7 @@ enum struct WorkerProto::Op : uint64_t
|
||||||
*/
|
*/
|
||||||
inline Sink & operator << (Sink & sink, WorkerProto::Op op)
|
inline Sink & operator << (Sink & sink, WorkerProto::Op op)
|
||||||
{
|
{
|
||||||
return sink << (uint64_t) op;
|
return sink << static_cast<uint64_t>(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -181,7 +181,7 @@ inline Sink & operator << (Sink & sink, WorkerProto::Op op)
|
||||||
*/
|
*/
|
||||||
inline std::ostream & operator << (std::ostream & s, WorkerProto::Op op)
|
inline std::ostream & operator << (std::ostream & s, WorkerProto::Op op)
|
||||||
{
|
{
|
||||||
return s << (uint64_t) op;
|
return s << static_cast<uint64_t>(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue