Skip to content

Commit 9c04c62

Browse files
committed
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.
1 parent 5b15544 commit 9c04c62

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

doc/manual/rl-next/json-format-changes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The store path info JSON format has been updated from version 1 to version 2:
2222
- New: `"ca": {"method": "nar", "hash": {"algorithm": "sha256", "format": "base64", "hash": "EMIJ+giQ..."}}`
2323
- Still `null` values for input-addressed store objects
2424

25-
Version 1 format is still accepted when reading for backward compatibility.
25+
Nix currently only produces, and doesn't consume this format.
2626

2727
**Affected command**: `nix path-info --json`
2828

src/libstore/derivation-options.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,6 @@ void adl_serializer<DerivationOptions>::to_json(json & json, const DerivationOpt
423423
json["allowSubstitutes"] = o.allowSubstitutes;
424424
}
425425

426-
template<typename T>
427-
static inline std::optional<T> ptrToOwned(const json * ptr)
428-
{
429-
if (ptr)
430-
return std::optional{*ptr};
431-
else
432-
return std::nullopt;
433-
}
434-
435426
DerivationOptions::OutputChecks adl_serializer<DerivationOptions::OutputChecks>::from_json(const json & json_)
436427
{
437428
auto & json = getObject(json_);

src/libstore/path-info.cc

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,10 @@ UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const StoreDirConfig & store
192192

193193
auto & json = getObject(_json);
194194

195-
// Check version (optional for backward compatibility)
196-
nlohmann::json::number_unsigned_t version = 1;
197-
if (json.contains("version")) {
198-
version = getUnsigned(valueAt(json, "version"));
199-
if (version != 1 && version != 2) {
200-
throw Error("Unsupported path info JSON format version %d, expected 1 through 2", version);
201-
}
195+
{
196+
auto version = getUnsigned(valueAt(json, "version"));
197+
if (version != 2)
198+
throw Error("Unsupported path info JSON format version %d, only version 2 is currently supported", version);
202199
}
203200

204201
res.narHash = Hash::parseAny(getString(valueAt(json, "narHash")), std::nullopt);
@@ -213,19 +210,12 @@ UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const StoreDirConfig & store
213210
throw;
214211
}
215212

216-
// New format as this as nullable but mandatory field; handling
217-
// missing is for back-compat.
218-
if (auto * rawCa0 = optionalValueAt(json, "ca"))
219-
if (auto * rawCa = getNullable(*rawCa0))
220-
switch (version) {
221-
case 1:
222-
// old string format also used in SQLite DB and .narinfo
223-
res.ca = ContentAddress::parse(getString(*rawCa));
224-
break;
225-
case 2 ... std::numeric_limits<decltype(version)>::max():
226-
res.ca = *rawCa;
227-
break;
228-
}
213+
try {
214+
res.ca = ptrToOwned<ContentAddress>(getNullable(valueAt(json, "ca")));
215+
} catch (Error & e) {
216+
e.addTrace({}, "while reading key 'ca'");
217+
throw;
218+
}
229219

230220
if (auto * rawDeriver0 = optionalValueAt(json, "deriver"))
231221
if (auto * rawDeriver = getNullable(*rawDeriver0))

src/libutil/include/nix/util/json-utils.hh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,13 @@ struct adl_serializer<std::optional<T>>
114114
}
115115
};
116116

117+
template<typename T>
118+
static inline std::optional<T> ptrToOwned(const json * ptr)
119+
{
120+
if (ptr)
121+
return std::optional{*ptr};
122+
else
123+
return std::nullopt;
124+
}
125+
117126
} // namespace nlohmann

0 commit comments

Comments
 (0)