Fix narinfo optional References; working install
This commit is contained in:
1 parent
b3d95bb012
commit
82c08d45b1
2 files changed
+29
-5
No files matched your search
@@ -24,7 +24,7 @@ fn parse_i64(key : String, v : String) -> Int64 raise @store.NixError {
|
|||||||
|
|
||||||
///|
|
///|
|
||||||
/// Parse the text of a narinfo file. Required keys: StorePath, URL,
|
/// Parse the text of a narinfo file. Required keys: StorePath, URL,
|
||||||
/// NarHash, NarSize, References. `Compression` defaults to "bzip2" when
|
/// NarHash, NarSize. `References` is optional (omitted when empty). `Compression` defaults to "bzip2" when
|
||||||
/// absent (per the Nix spec); unsupported values fail at decompression time.
|
/// absent (per the Nix spec); unsupported values fail at decompression time.
|
||||||
/// Duplicate keys (except `Sig`, which may repeat) and malformed lines are
|
/// Duplicate keys (except `Sig`, which may repeat) and malformed lines are
|
||||||
/// errors.
|
/// errors.
|
||||||
@@ -36,11 +36,14 @@ pub fn NarInfo::parse(text : String) -> NarInfo raise @store.NixError {
|
|||||||
if line.length() == 0 {
|
if line.length() == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
guard line.find(": ") is Some(i) else {
|
// "Key: value", or "Key:" alone when the value is empty (e.g. no references)
|
||||||
|
let (key, value) = if line.find(": ") is Some(i) {
|
||||||
|
(line[0:i].to_owned(), line[i + 2:].to_owned())
|
||||||
|
} else if line.has_suffix(":") {
|
||||||
|
(line[0:line.length() - 1].to_owned(), "")
|
||||||
|
} else {
|
||||||
raise Parse("narinfo: malformed line (no ': '): \{line}")
|
raise Parse("narinfo: malformed line (no ': '): \{line}")
|
||||||
}
|
}
|
||||||
let key = line[0:i].to_owned()
|
|
||||||
let value = line[i + 2:].to_owned()
|
|
||||||
if key == "Sig" {
|
if key == "Sig" {
|
||||||
sigs.push(value)
|
sigs.push(value)
|
||||||
continue
|
continue
|
||||||
@@ -75,7 +78,8 @@ pub fn NarInfo::parse(text : String) -> NarInfo raise @store.NixError {
|
|||||||
.filter(fn(s) { s.length() > 0 })
|
.filter(fn(s) { s.length() > 0 })
|
||||||
.map(fn(s) { s.to_owned() })
|
.map(fn(s) { s.to_owned() })
|
||||||
.collect()
|
.collect()
|
||||||
None => raise Parse("narinfo: missing required key References")
|
// cache.nixos.org omits the line entirely when there are no references
|
||||||
|
None => []
|
||||||
}
|
}
|
||||||
for r in references {
|
for r in references {
|
||||||
ignore(@store.StorePath::parse_base(r))
|
ignore(@store.StorePath::parse_base(r))
|
||||||
|
|||||||
@@ -36,3 +36,23 @@ test "reject malformed narinfo" {
|
|||||||
assert_true(@store.raises(() => NarInfo::parse("URL: a\nURL: b\n")))
|
assert_true(@store.raises(() => NarInfo::parse("URL: a\nURL: b\n")))
|
||||||
assert_true(@store.raises(() => NarInfo::parse("URL: a\n")))
|
assert_true(@store.raises(() => NarInfo::parse("URL: a\n")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "empty References value" {
|
||||||
|
let ni = NarInfo::parse(
|
||||||
|
"StorePath: /nix/store/8padfyi6z9ipfq35j86krpvpvx3j3r3v-x-1\nURL: nar/a.nar.xz\nCompression: xz\nNarHash: sha256:00\nNarSize: 5\nReferences:\n",
|
||||||
|
)
|
||||||
|
assert_eq(ni.references.length(), 0)
|
||||||
|
let ni2 = NarInfo::parse(
|
||||||
|
"StorePath: /nix/store/8padfyi6z9ipfq35j86krpvpvx3j3r3v-x-1\nURL: nar/a.nar.xz\nCompression: xz\nNarHash: sha256:00\nNarSize: 5\nReferences: \n",
|
||||||
|
)
|
||||||
|
assert_eq(ni2.references.length(), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "absent References line means no references (as served by the real cache)" {
|
||||||
|
let ni = NarInfo::parse(
|
||||||
|
"StorePath: /nix/store/80v5n8kdscr9r2ls8h72s8ppwmccwrgm-xgcc-16.2.0-libgcc\nURL: nar/a.nar.zst\nCompression: zstd\nNarHash: sha256:00\nNarSize: 5\n",
|
||||||
|
)
|
||||||
|
assert_eq(ni.references.length(), 0)
|
||||||
|
}
|
||||||
Reference in new issue
Block a user