about summary refs log tree commit diff
path: root/tvix/nar-bridge/pkg
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-10-09T10·07+0200
committerclbot <clbot@tvl.fyi>2023-10-09T22·05+0000
commit78abeaa92074f934e14845fbb95fb8218c72ee9f (patch)
treec1cc4bbcd055d5fc961096add295f7f57458dd2a /tvix/nar-bridge/pkg
parent28cd4b1a2f98759dc33390db78f328f20f2db515 (diff)
refactor(tvix/nar-bridge): use storepath for store paths r/6759
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 <flokli@flokli.de>
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Diffstat (limited to 'tvix/nar-bridge/pkg')
-rw-r--r--tvix/nar-bridge/pkg/pathinfosvc/server.go32
1 files changed, 13 insertions, 19 deletions
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")
 	}