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 <flokli@flokli.de> Reviewed-by: Connor Brewster <cbrewster@hey.com>
This commit is contained in:
parent
28cd4b1a2f
commit
78abeaa920
1 changed files with 13 additions and 19 deletions
|
@ -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)
|
||||
// extract the output digests
|
||||
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])
|
||||
referenceStorePath, err := storepath.FromString(referenceStr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to decode reference string '%s': %w", referenceStr, err)
|
||||
return nil, fmt.Errorf("unable to parse %s as StorePath: %w", referenceStr, err)
|
||||
}
|
||||
|
||||
pathInfo.References = append(pathInfo.References, referenceStorePath.Digest)
|
||||
}
|
||||
pathInfo.References = append(pathInfo.References, decodedReferenceHash)
|
||||
}
|
||||
}
|
||||
|
||||
// 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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue