feat(tvix/store/protos): add Deriver field to PathInfo
This uses the newly introduced StorePath message type to add a Deriver field to the PathInfo message. Support for validation is added to both the golang and rust implementation. This includes extending unit tests. Change-Id: Ifc3eb3263fa25b9eec260db354cd74234c40af7e Reviewed-on: https://cl.tvl.fyi/c/depot/+/9647 Reviewed-by: Connor Brewster <cbrewster@hey.com> Tested-by: BuildkiteCI
This commit is contained in:
parent
5f8eb4eeaa
commit
2d2c4322d9
10 changed files with 161 additions and 39 deletions
|
|
@ -60,42 +60,55 @@ func (p *PathInfo) Validate() (*storepath.StorePath, error) {
|
|||
// for all three node types, ensure the name properly parses to a store path,
|
||||
// and in case it refers to a digest, ensure it has the right length.
|
||||
|
||||
var storePath *storepath.StorePath
|
||||
var err error
|
||||
|
||||
if node := rootNode.GetDirectory(); node != nil {
|
||||
if len(node.Digest) != 32 {
|
||||
return nil, fmt.Errorf("invalid digest size for %s, expected %d, got %d", node.Name, 32, len(node.Digest))
|
||||
}
|
||||
|
||||
storePath, err := storepath.FromString(string(node.GetName()))
|
||||
storePath, err = storepath.FromString(string(node.GetName()))
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse %s as StorePath: %w", node.Name, err)
|
||||
}
|
||||
|
||||
return storePath, nil
|
||||
|
||||
} else if node := rootNode.GetFile(); node != nil {
|
||||
if len(node.Digest) != 32 {
|
||||
return nil, fmt.Errorf("invalid digest size for %s, expected %d, got %d", node.Name, 32, len(node.Digest))
|
||||
}
|
||||
|
||||
storePath, err := storepath.FromString(string(node.GetName()))
|
||||
storePath, err = storepath.FromString(string(node.GetName()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse %s as StorePath: %w", node.Name, err)
|
||||
}
|
||||
|
||||
return storePath, nil
|
||||
|
||||
} else if node := rootNode.GetSymlink(); node != nil {
|
||||
storePath, err := storepath.FromString(string(node.GetName()))
|
||||
storePath, err = storepath.FromString(string(node.GetName()))
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse %s as StorePath: %w", node.Name, err)
|
||||
}
|
||||
|
||||
return storePath, nil
|
||||
|
||||
} else {
|
||||
// this would only happen if we introduced a new type
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
// If the Deriver field is populated, ensure it parses to a StorePath.
|
||||
// We can't check for it to *not* end with .drv, as the .drv files produced by
|
||||
// recursive Nix end with multiple .drv suffixes, and only one is popped when
|
||||
// converting to this field.
|
||||
if p.Deriver != nil {
|
||||
storePath := storepath.StorePath{
|
||||
Name: string(p.Deriver.GetName()),
|
||||
Digest: p.Deriver.GetDigest(),
|
||||
}
|
||||
if err := storePath.Validate(); err != nil {
|
||||
return nil, fmt.Errorf("invalid deriver field: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return storePath, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue