From 78abeaa92074f934e14845fbb95fb8218c72ee9f Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 9 Oct 2023 12:07:51 +0200 Subject: refactor(tvix/nar-bridge): use storepath for store paths Remove the handwritten parsing and formatting of store paths. Change-Id: Ia4ba486b4363c33b98937bcbf6f5f7bcda289b82 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9588 Tested-by: BuildkiteCI Autosubmit: flokli Reviewed-by: Connor Brewster --- tvix/nar-bridge/pkg/pathinfosvc/server.go | 32 +++++++++++++------------------ 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'tvix/nar-bridge/pkg/pathinfosvc') diff --git a/tvix/nar-bridge/pkg/pathinfosvc/server.go b/tvix/nar-bridge/pkg/pathinfosvc/server.go index d5074a2f3267..c452237f2693 100644 --- a/tvix/nar-bridge/pkg/pathinfosvc/server.go +++ b/tvix/nar-bridge/pkg/pathinfosvc/server.go @@ -218,25 +218,20 @@ func (p *PathInfoServiceServer) Get(ctx context.Context, getPathInfoRequest *sto // annotate importedPathInfo with the rest of the metadata from NARINfo. - // extract the output hashes from narInfo.References into importedPathInfo.References. - { - // Length of the hash portion of the store path in base32. - encodedPathHashSize := nixbase32.EncodedLen(20) - for _, referenceStr := range narInfo.References { - if len(referenceStr) < encodedPathHashSize { - return nil, fmt.Errorf("reference string '%s' is too small", referenceStr) - } - - decodedReferenceHash, err := nixbase32.DecodeString(referenceStr[0:encodedPathHashSize]) - if err != nil { - return nil, fmt.Errorf("unable to decode reference string '%s': %w", referenceStr, err) - - } - pathInfo.References = append(pathInfo.References, decodedReferenceHash) + // extract the output digests + for _, referenceStr := range narInfo.References { + referenceStorePath, err := storepath.FromString(referenceStr) + if err != nil { + return nil, fmt.Errorf("unable to parse %s as StorePath: %w", referenceStr, err) } + + pathInfo.References = append(pathInfo.References, referenceStorePath.Digest) } + + // extract narInfo.References into pathInfo.NarInfo.ReferenceNames. pathInfo.Narinfo.ReferenceNames = narInfo.References + // copy over signatures from narInfo.signatures into pathInfo.NarInfo.Signatures. for _, signature := range narInfo.Signatures { pathInfo.Narinfo.Signatures = append(pathInfo.Narinfo.Signatures, &storev1pb.NARInfo_Signature{ Name: signature.Name, @@ -251,15 +246,14 @@ func (p *PathInfoServiceServer) Get(ctx context.Context, getPathInfoRequest *sto // unreachable due to narInfo.Check() panic(err) } - newName := []byte(nixbase32.EncodeToString(outPath.Digest) + "-" + string(outPath.Name)) // set the root name in all three cases. if node := pathInfo.Node.GetDirectory(); node != nil { - node.Name = newName + node.Name = []byte(outPath.String()) } else if node := pathInfo.Node.GetFile(); node != nil { - node.Name = newName + node.Name = []byte(outPath.String()) } else if node := pathInfo.Node.GetSymlink(); node != nil { - node.Name = newName + node.Name = []byte(outPath.String()) } else { panic("node may not be nil") } -- cgit 1.4.1