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

Fixup issues with bytes

This commit is contained in:
John Ericson 2025-10-23 13:49:54 -04:00
parent 04edfa34fe
commit e59b4c69f1
2 changed files with 7 additions and 5 deletions

View file

@ -1,6 +1,7 @@
#include <gtest/gtest.h>
#include <nlohmann/json.hpp>
#include "nix/util/bytes.hh"
#include "nix/util/memory-source-accessor.hh"
#include "nix/store/dummy-store-impl.hh"
#include "nix/store/globals.hh"
@ -105,7 +106,7 @@ INSTANTIATE_TEST_SUITE_P(DummyStoreJSON, DummyStoreJsonTest, [] {
auto sc = make_ref<MemorySourceAccessor>();
sc->root = MemorySourceAccessor::File{MemorySourceAccessor::File::Regular{
.executable = false,
.contents = "asdf",
.contents = to_owned(as_bytes("asdf")),
}};
return sc;
}(),

View file

@ -1,5 +1,6 @@
#include "nix/store/store-registration.hh"
#include "nix/util/archive.hh"
#include "nix/util/bytes.hh"
#include "nix/util/callback.hh"
#include "nix/util/memory-source-accessor.hh"
#include "nix/util/json-utils.hh"
@ -153,7 +154,7 @@ struct DummyStoreImpl : DummyStore
/* compute path info on demand */
auto accessor = make_ref<MemorySourceAccessor>();
accessor->root = MemorySourceAccessor::File::Regular{
.contents = kv.second.unparse(*this, false),
.contents = to_owned(as_bytes(kv.second.unparse(*this, false))),
};
auto narHash = hashPath(
{accessor, CanonPath::root}, FileSerialisationMethod::NixArchive, HashAlgorithm::SHA256);
@ -164,7 +165,7 @@ struct DummyStoreImpl : DummyStore
.method = ContentAddressMethod::Raw::Text,
.hash = hashString(
HashAlgorithm::SHA256,
std::get<MemorySourceAccessor::File::Regular>(accessor->root->raw).contents),
to_str(std::get<MemorySourceAccessor::File::Regular>(accessor->root->raw).contents)),
};
callback(std::move(info));
}))
@ -429,7 +430,7 @@ ref<DummyStore> adl_serializer<ref<DummyStore>>::from_json(const json & json)
auto vref = make_ref<UnkeyedRealisation>(v2);
res->buildTrace.insert_or_visit(
{
Hash::parseExplicitFormatUnprefixed(k0, HashAlgorithm::SHA256, HashFormat::Base64),
StorePath{k0},
{{k1, vref}},
},
[&](auto & kv) { kv.second.insert_or_assign(k1, vref); });
@ -465,7 +466,7 @@ void adl_serializer<ref<DummyStore>>::to_json(json & json, const ref<DummyStore>
auto obj = json::object();
val->buildTrace.cvisit_all([&](const auto & kv) {
auto & [k, v] = kv;
auto & obj2 = obj[k.to_string(HashFormat::Base64, false)] = json::object();
auto & obj2 = obj[k.to_string()] = json::object();
for (auto & [k2, v2] : kv.second)
obj2[k2] = *v2;
});