1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

UnkeyedValidPathInfo::fromJSON Remove support for older version

It turns out this code path is only used for unit tests (to ensure our
JSON formats are possible to parse by other code, elsewhere). No
user-facing functionality consumes this format.

Therefore, let's drop the old version parsing support.
This commit is contained in:
John Ericson 2025-11-06 16:51:19 -05:00
parent 5b15544bdd
commit 9c04c629e5
4 changed files with 20 additions and 30 deletions

View file

@ -22,7 +22,7 @@ The store path info JSON format has been updated from version 1 to version 2:
- New: `"ca": {"method": "nar", "hash": {"algorithm": "sha256", "format": "base64", "hash": "EMIJ+giQ..."}}` - New: `"ca": {"method": "nar", "hash": {"algorithm": "sha256", "format": "base64", "hash": "EMIJ+giQ..."}}`
- Still `null` values for input-addressed store objects - Still `null` values for input-addressed store objects
Version 1 format is still accepted when reading for backward compatibility. Nix currently only produces, and doesn't consume this format.
**Affected command**: `nix path-info --json` **Affected command**: `nix path-info --json`

View file

@ -423,15 +423,6 @@ void adl_serializer<DerivationOptions>::to_json(json & json, const DerivationOpt
json["allowSubstitutes"] = o.allowSubstitutes; json["allowSubstitutes"] = o.allowSubstitutes;
} }
template<typename T>
static inline std::optional<T> ptrToOwned(const json * ptr)
{
if (ptr)
return std::optional{*ptr};
else
return std::nullopt;
}
DerivationOptions::OutputChecks adl_serializer<DerivationOptions::OutputChecks>::from_json(const json & json_) DerivationOptions::OutputChecks adl_serializer<DerivationOptions::OutputChecks>::from_json(const json & json_)
{ {
auto & json = getObject(json_); auto & json = getObject(json_);

View file

@ -192,13 +192,10 @@ UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const StoreDirConfig & store
auto & json = getObject(_json); auto & json = getObject(_json);
// Check version (optional for backward compatibility) {
nlohmann::json::number_unsigned_t version = 1; auto version = getUnsigned(valueAt(json, "version"));
if (json.contains("version")) { if (version != 2)
version = getUnsigned(valueAt(json, "version")); throw Error("Unsupported path info JSON format version %d, only version 2 is currently supported", version);
if (version != 1 && version != 2) {
throw Error("Unsupported path info JSON format version %d, expected 1 through 2", version);
}
} }
res.narHash = Hash::parseAny(getString(valueAt(json, "narHash")), std::nullopt); res.narHash = Hash::parseAny(getString(valueAt(json, "narHash")), std::nullopt);
@ -213,18 +210,11 @@ UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const StoreDirConfig & store
throw; throw;
} }
// New format as this as nullable but mandatory field; handling try {
// missing is for back-compat. res.ca = ptrToOwned<ContentAddress>(getNullable(valueAt(json, "ca")));
if (auto * rawCa0 = optionalValueAt(json, "ca")) } catch (Error & e) {
if (auto * rawCa = getNullable(*rawCa0)) e.addTrace({}, "while reading key 'ca'");
switch (version) { throw;
case 1:
// old string format also used in SQLite DB and .narinfo
res.ca = ContentAddress::parse(getString(*rawCa));
break;
case 2 ... std::numeric_limits<decltype(version)>::max():
res.ca = *rawCa;
break;
} }
if (auto * rawDeriver0 = optionalValueAt(json, "deriver")) if (auto * rawDeriver0 = optionalValueAt(json, "deriver"))

View file

@ -114,4 +114,13 @@ struct adl_serializer<std::optional<T>>
} }
}; };
template<typename T>
static inline std::optional<T> ptrToOwned(const json * ptr)
{
if (ptr)
return std::optional{*ptr};
else
return std::nullopt;
}
} // namespace nlohmann } // namespace nlohmann