dropEmptyInitThenConcatStringsSep -> concatStringSep: shortRefs are not empty

This commit is contained in:
Robert Hensing 2024-07-13 00:50:39 +02:00
parent 608a425550
commit d3e49ac881
4 changed files with 20 additions and 4 deletions

View File

@ -339,7 +339,7 @@ public:
(narInfo ? narInfo->fileSize : 0, narInfo != 0 && narInfo->fileSize) (narInfo ? narInfo->fileSize : 0, narInfo != 0 && narInfo->fileSize)
(info->narHash.to_string(HashFormat::Nix32, true)) (info->narHash.to_string(HashFormat::Nix32, true))
(info->narSize) (info->narSize)
(dropEmptyInitThenConcatStringsSep(" ", info->shortRefs())) (concatStringsSep(" ", info->shortRefs()))
(info->deriver ? std::string(info->deriver->to_string()) : "", (bool) info->deriver) (info->deriver ? std::string(info->deriver->to_string()) : "", (bool) info->deriver)
(concatStringsSep(" ", info->sigs)) (concatStringsSep(" ", info->sigs))
(renderContentAddress(info->ca)) (renderContentAddress(info->ca))

View File

@ -1,6 +1,7 @@
#include "globals.hh" #include "globals.hh"
#include "nar-info.hh" #include "nar-info.hh"
#include "store-api.hh" #include "store-api.hh"
#include "strings.hh"
namespace nix { namespace nix {
@ -111,7 +112,7 @@ std::string NarInfo::to_string(const Store & store) const
res += "NarHash: " + narHash.to_string(HashFormat::Nix32, true) + "\n"; res += "NarHash: " + narHash.to_string(HashFormat::Nix32, true) + "\n";
res += "NarSize: " + std::to_string(narSize) + "\n"; res += "NarSize: " + std::to_string(narSize) + "\n";
res += "References: " + dropEmptyInitThenConcatStringsSep(" ", shortRefs()) + "\n"; res += "References: " + concatStringsSep(" ", shortRefs()) + "\n";
if (deriver) if (deriver)
res += "Deriver: " + std::string(deriver->to_string()) + "\n"; res += "Deriver: " + std::string(deriver->to_string()) + "\n";

View File

@ -171,6 +171,9 @@ struct ValidPathInfo : UnkeyedValidPathInfo {
*/ */
bool checkSignature(const Store & store, const PublicKeys & publicKeys, const std::string & sig) const; bool checkSignature(const Store & store, const PublicKeys & publicKeys, const std::string & sig) const;
/**
* References as store path basenames, including a self reference if it has one.
*/
Strings shortRefs() const; Strings shortRefs() const;
ValidPathInfo(const ValidPathInfo & other) = default; ValidPathInfo(const ValidPathInfo & other) = default;

View File

@ -26,9 +26,9 @@ static UnkeyedValidPathInfo makeEmpty()
}; };
} }
static UnkeyedValidPathInfo makeFull(const Store & store, bool includeImpureInfo) static ValidPathInfo makeFullKeyed(const Store & store, bool includeImpureInfo)
{ {
UnkeyedValidPathInfo info = ValidPathInfo { ValidPathInfo info = ValidPathInfo {
store, store,
"foo", "foo",
FixedOutputInfo { FixedOutputInfo {
@ -57,6 +57,9 @@ static UnkeyedValidPathInfo makeFull(const Store & store, bool includeImpureInfo
} }
return info; return info;
} }
static UnkeyedValidPathInfo makeFull(const Store & store, bool includeImpureInfo) {
return makeFullKeyed(store, includeImpureInfo);
}
#define JSON_TEST(STEM, OBJ, PURE) \ #define JSON_TEST(STEM, OBJ, PURE) \
TEST_F(PathInfoTest, PathInfo_ ## STEM ## _from_json) { \ TEST_F(PathInfoTest, PathInfo_ ## STEM ## _from_json) { \
@ -86,4 +89,13 @@ JSON_TEST(empty_impure, makeEmpty(), true)
JSON_TEST(pure, makeFull(*store, false), false) JSON_TEST(pure, makeFull(*store, false), false)
JSON_TEST(impure, makeFull(*store, true), true) JSON_TEST(impure, makeFull(*store, true), true)
TEST_F(PathInfoTest, PathInfo_full_shortRefs) {
ValidPathInfo it = makeFullKeyed(*store, true);
// it.references = unkeyed.references;
auto refs = it.shortRefs();
ASSERT_EQ(refs.size(), 2);
ASSERT_EQ(*refs.begin(), "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar");
ASSERT_EQ(*++refs.begin(), "n5wkd9frr45pa74if5gpz9j7mifg27fh-foo");
} }
} // namespace nix