go/nix/nar: move narinfo to go/nix/nar/narinfo

This commit is contained in:
Luke Granger-Brown 2021-07-27 22:06:59 +01:00
parent 50520f0230
commit e44e0f128e
4 changed files with 30 additions and 13 deletions

View file

@ -2,13 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0
{ depot, ... }:
depot.third_party.buildGo.package {
name = "nar";
srcs = [
./narinfo.go
];
deps = with depot; [
third_party.gopkgs."github.com".numtide.go-nix.nixbase32
];
args:
{
narinfo = import ./narinfo args;
}

View file

@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2020 Luke Granger-Brown <depot@lukegb.com>
#
# SPDX-License-Identifier: Apache-2.0
{ depot, ... }:
depot.third_party.buildGo.package {
name = "narinfo";
srcs = [
./narinfo.go
];
deps = with depot; [
third_party.gopkgs."github.com".numtide.go-nix.nixbase32
];
}

View file

@ -2,8 +2,8 @@
//
// SPDX-License-Identifier: Apache-2.0
// Package nar implements a simple NAR read/writer.
package nar
// Package narinfo implements a simple narinfo read/writer.
package narinfo
import (
"bufio"
@ -207,6 +207,7 @@ type NarInfo struct {
Deriver string
System string
Sig map[string][]byte
CA string
}
func (ni NarInfo) WriteTo(w io.Writer) error {
@ -273,6 +274,11 @@ func (ni NarInfo) WriteTo(w io.Writer) error {
}
}
}
if ni.CA != "" {
if _, err := fmt.Fprintf(w, "CA: %s\n", ni.CA); err != nil {
return err
}
}
return nil
}
@ -335,6 +341,9 @@ func ParseNarInfo(r io.Reader) (*NarInfo, error) {
}
case "References":
ni.References = strings.Split(value, " ")
if len(ni.References) == 1 && ni.References[0] == "" {
ni.References = nil
}
case "Deriver":
if value != "unknown-deriver" {
ni.Deriver = value
@ -355,7 +364,7 @@ func ParseNarInfo(r io.Reader) (*NarInfo, error) {
}
ni.Sig[bits[0]] = rawVal
case "CA":
return nil, fmt.Errorf("content-addressed NARs not supported yet")
ni.CA = value
}
}
if err := s.Err(); err != nil {

View file

@ -1,4 +1,4 @@
package nar
package narinfo
import (
"strings"