about summary refs log tree commit diff
path: root/tvix/store/protos/pathinfo.go
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-10-10T22·22+0200
committerflokli <flokli@flokli.de>2023-10-14T13·23+0000
commit2d2c4322d93308ddffe1647466abd91025af6a68 (patch)
tree37ead8574df6eb98d76ca95636b50bf8fe1945cb /tvix/store/protos/pathinfo.go
parent5f8eb4eeaaad31aedc45efee3143e6b0bbc982a4 (diff)
feat(tvix/store/protos): add Deriver field to PathInfo r/6805
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
Diffstat (limited to 'tvix/store/protos/pathinfo.go')
-rw-r--r--tvix/store/protos/pathinfo.go31
1 files changed, 22 insertions, 9 deletions
diff --git a/tvix/store/protos/pathinfo.go b/tvix/store/protos/pathinfo.go
index 2c718c6245d5..9b51b5266cdc 100644
--- a/tvix/store/protos/pathinfo.go
+++ b/tvix/store/protos/pathinfo.go
@@ -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
 }