Skip to content

Commit

Permalink
Rename LegacyContentAddress and related functions
Browse files Browse the repository at this point in the history
  • Loading branch information
meditans committed Jul 14, 2020
1 parent ade0f1a commit 08bf6c4
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 33 deletions.
16 changes: 8 additions & 8 deletions src/libstore/content-address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ std::string makeFileIngestionPrefix(const FileIngestionMethod m) {
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;

std::string renderLegacyContentAddress(LegacyContentAddress ca) {
std::string renderContentAddress(ContentAddress ca) {
return std::visit(overloaded {
[](TextHash th) {
return "text:"
Expand All @@ -35,15 +35,15 @@ std::string renderLegacyContentAddress(LegacyContentAddress ca) {
}, ca);
}

LegacyContentAddress parseLegacyContentAddress(std::string_view rawCa) {
ContentAddress parseContentAddress(std::string_view rawCa) {
auto prefixSeparator = rawCa.find(':');
if (prefixSeparator != string::npos) {
auto prefix = string(rawCa, 0, prefixSeparator);
if (prefix == "text") {
auto hashTypeAndHash = rawCa.substr(prefixSeparator+1, string::npos);
Hash hash = Hash(string(hashTypeAndHash));
if (*hash.type != htSHA256) {
throw Error("parseLegacyContentAddress: the text hash should have type SHA256");
throw Error("parseContentAddress: the text hash should have type SHA256");
}
return TextHash { hash };
} else if (prefix == "fixed") {
Expand All @@ -62,19 +62,19 @@ LegacyContentAddress parseLegacyContentAddress(std::string_view rawCa) {
};
}
} else {
throw Error("parseLegacyContentAddress: format not recognized; has to be text or fixed");
throw Error("parseContentAddress: format not recognized; has to be text or fixed");
}
} else {
throw Error("Not a content address because it lacks an appropriate prefix");
}
};

std::optional<LegacyContentAddress> parseLegacyContentAddressOpt(std::string_view rawCaOpt) {
return rawCaOpt == "" ? std::optional<LegacyContentAddress> {} : parseLegacyContentAddress(rawCaOpt);
std::optional<ContentAddress> parseContentAddressOpt(std::string_view rawCaOpt) {
return rawCaOpt == "" ? std::optional<ContentAddress> {} : parseContentAddress(rawCaOpt);
};

std::string renderLegacyContentAddress(std::optional<LegacyContentAddress> ca) {
return ca ? renderLegacyContentAddress(*ca) : "";
std::string renderContentAddress(std::optional<ContentAddress> ca) {
return ca ? renderContentAddress(*ca) : "";
}

}
10 changes: 5 additions & 5 deletions src/libstore/content-address.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ struct FixedOutputHash {
typedef std::variant<
TextHash, // for paths computed by makeTextPath() / addTextToStore
FixedOutputHash // for path computed by makeFixedOutputPath
> LegacyContentAddress;
> ContentAddress;

/* Compute the prefix to the hash algorithm which indicates how the files were
ingested. */
std::string makeFileIngestionPrefix(const FileIngestionMethod m);

std::string renderLegacyContentAddress(LegacyContentAddress ca);
std::string renderContentAddress(ContentAddress ca);

std::string renderLegacyContentAddress(std::optional<LegacyContentAddress> ca);
std::string renderContentAddress(std::optional<ContentAddress> ca);

LegacyContentAddress parseLegacyContentAddress(std::string_view rawCa);
ContentAddress parseContentAddress(std::string_view rawCa);

std::optional<LegacyContentAddress> parseLegacyContentAddressOpt(std::string_view rawCaOpt);
std::optional<ContentAddress> parseContentAddressOpt(std::string_view rawCaOpt);

/*
* References set
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
if (GET_PROTOCOL_MINOR(clientVersion) >= 16) {
to << info->ultimate
<< info->sigs
<< renderLegacyContentAddress(info->ca);
<< renderContentAddress(info->ca);
}
} else {
assert(GET_PROTOCOL_MINOR(clientVersion) >= 17);
Expand Down Expand Up @@ -722,7 +722,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
info.setReferencesPossiblyToSelf(readStorePaths<StorePathSet>(*store, from));
from >> info.registrationTime >> info.narSize >> info.ultimate;
info.sigs = readStrings<StringSet>(from);
info.ca = parseLegacyContentAddressOpt(readString(from));
info.ca = parseContentAddressOpt(readString(from));
from >> repair >> dontCheckSigs;
if (!trusted && dontCheckSigs)
dontCheckSigs = false;
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct LegacySSHStore : public Store
if (GET_PROTOCOL_MINOR(conn->remoteVersion) >= 4) {
auto s = readString(conn->from);
info->narHash = s.empty() ? Hash() : Hash(s);
info->ca = parseLegacyContentAddressOpt(readString(conn->from));
info->ca = parseContentAddressOpt(readString(conn->from));
info->sigs = readStrings<StringSet>(conn->from);
}

Expand Down Expand Up @@ -145,7 +145,7 @@ struct LegacySSHStore : public Store
<< info.narSize
<< info.ultimate
<< info.sigs
<< renderLegacyContentAddress(info.ca);
<< renderContentAddress(info.ca);
try {
copyNAR(source, conn->to);
} catch (...) {
Expand Down
6 changes: 3 additions & 3 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ uint64_t LocalStore::addValidPath(State & state,
(info.narSize, info.narSize != 0)
(info.ultimate ? 1 : 0, info.ultimate)
(concatStringsSep(" ", info.sigs), !info.sigs.empty())
(renderLegacyContentAddress(info.ca), (bool) info.ca)
(renderContentAddress(info.ca), (bool) info.ca)
.exec();
uint64_t id = sqlite3_last_insert_rowid(state.db);

Expand Down Expand Up @@ -666,7 +666,7 @@ void LocalStore::queryPathInfoUncached(const StorePath & path,
if (s) info->sigs = tokenizeString<StringSet>(s, " ");

s = (const char *) sqlite3_column_text(state->stmtQueryPathInfo, 7);
if (s) info->ca = parseLegacyContentAddressOpt(s);
if (s) info->ca = parseContentAddressOpt(s);

/* Get the references. */
auto useQueryReferences(state->stmtQueryReferences.use()(info->id));
Expand All @@ -691,7 +691,7 @@ void LocalStore::updatePathInfo(State & state, const ValidPathInfo & info)
(info.narHash.to_string(Base16, true))
(info.ultimate ? 1 : 0, info.ultimate)
(concatStringsSep(" ", info.sigs), !info.sigs.empty())
(renderLegacyContentAddress(info.ca), (bool) info.ca)
(renderContentAddress(info.ca), (bool) info.ca)
(printStorePath(info.path))
.exec();
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/nar-info-disk-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache
narInfo->deriver = StorePath(queryNAR.getStr(9));
for (auto & sig : tokenizeString<Strings>(queryNAR.getStr(10), " "))
narInfo->sigs.insert(sig);
narInfo->ca = parseLegacyContentAddressOpt(queryNAR.getStr(11));
narInfo->ca = parseContentAddressOpt(queryNAR.getStr(11));

return {oValid, narInfo};
});
Expand Down Expand Up @@ -237,7 +237,7 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache
(concatStringsSep(" ", info->shortRefs()))
(info->deriver ? std::string(info->deriver->to_string()) : "", (bool) info->deriver)
(concatStringsSep(" ", info->sigs))
(renderLegacyContentAddress(info->ca))
(renderContentAddress(info->ca))
(time(0)).exec();

} else {
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/nar-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &
else if (name == "CA") {
if (ca) corrupt();
// FIXME: allow blank ca or require skipping field?
ca = parseLegacyContentAddressOpt(value);
ca = parseContentAddressOpt(value);
}

pos = eol + 1;
Expand Down Expand Up @@ -107,7 +107,7 @@ std::string NarInfo::to_string(const Store & store) const
res += "Sig: " + sig + "\n";

if (ca)
res += "CA: " + renderLegacyContentAddress(*ca) + "\n";
res += "CA: " + renderContentAddress(*ca) + "\n";

return res;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/path-info.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct ValidPathInfo : PathReferences<StorePath>
and the store path would be computed from the name component, ‘narHash’
and ‘references’. However, we support many types of content addresses.
*/
std::optional<LegacyContentAddress> ca;
std::optional<ContentAddress> ca;

bool operator == (const ValidPathInfo & i) const
{
Expand Down
8 changes: 4 additions & 4 deletions src/libstore/remote-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ std::set<StorePathDescriptor> readStorePathDescriptorSet(const Store & store, So
// TODO
// auto count = readNum<size_t>(from);
// while (count--)
// paths.insert_or_assign(store.parseStorePath(readString(from)), parseLegacyContentAddressOpt(readString(from)));
// paths.insert_or_assign(store.parseStorePath(readString(from)), parseContentAddressOpt(readString(from)));
return paths;
}

Expand All @@ -55,7 +55,7 @@ void writeStorePathDescriptorSet(const Store & store, Sink & out, const std::set
//out << paths.size();
//for (auto & i : paths) {
// out << store.printStorePath(i.first);
// out << renderLegacyContentAddress(i.second);
// out << renderContentAddress(i.second);
//}
}

Expand Down Expand Up @@ -436,7 +436,7 @@ void RemoteStore::queryPathInfoUncached(const StorePath & path,
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 16) {
conn->from >> info->ultimate;
info->sigs = readStrings<StringSet>(conn->from);
info->ca = parseLegacyContentAddressOpt(readString(conn->from));
info->ca = parseContentAddressOpt(readString(conn->from));
}
}
callback(std::move(info));
Expand Down Expand Up @@ -532,7 +532,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
<< info.narHash.to_string(Base16, false);
writeStorePaths(*this, conn->to, info.referencesPossiblyToSelf());
conn->to << info.registrationTime << info.narSize
<< info.ultimate << info.sigs << renderLegacyContentAddress(info.ca)
<< info.ultimate << info.sigs << renderContentAddress(info.ca)
<< repair << !checkSigs;
bool tunnel = GET_PROTOCOL_MINOR(conn->daemonVersion) >= 21;
if (!tunnel) copyNAR(source, conn->to);
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/store-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const StorePathSet & store
}

if (info->ca)
jsonPath.attr("ca", renderLegacyContentAddress(info->ca));
jsonPath.attr("ca", renderContentAddress(info->ca));

std::pair<uint64_t, uint64_t> closureSizes;

Expand Down
4 changes: 2 additions & 2 deletions src/nix-store/nix-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ static void opServe(Strings opFlags, Strings opArgs)
out << info->narSize // downloadSize
<< info->narSize;
if (GET_PROTOCOL_MINOR(clientVersion) >= 4)
out << (info->narHash ? info->narHash.to_string(Base32, true) : "") << renderLegacyContentAddress(info->ca) << info->sigs;
out << (info->narHash ? info->narHash.to_string(Base32, true) : "") << renderContentAddress(info->ca) << info->sigs;
} catch (InvalidPath &) {
}
}
Expand Down Expand Up @@ -958,7 +958,7 @@ static void opServe(Strings opFlags, Strings opArgs)
info.setReferencesPossiblyToSelf(readStorePaths<StorePathSet>(*store, in));
in >> info.registrationTime >> info.narSize >> info.ultimate;
info.sigs = readStrings<StringSet>(in);
info.ca = parseLegacyContentAddressOpt(readString(in));
info.ca = parseContentAddressOpt(readString(in));

if (info.narSize == 0)
throw Error("narInfo is too old and missing the narSize field");
Expand Down
2 changes: 1 addition & 1 deletion src/nix/path-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
std::cout << '\t';
Strings ss;
if (info->ultimate) ss.push_back("ultimate");
if (info->ca) ss.push_back("ca:" + renderLegacyContentAddress(*info->ca));
if (info->ca) ss.push_back("ca:" + renderContentAddress(*info->ca));
for (auto & sig : info->sigs) ss.push_back(sig);
std::cout << concatStringsSep(" ", ss);
}
Expand Down

0 comments on commit 08bf6c4

Please sign in to comment.