about summary refs log tree commit diff
path: root/tvix/nar-bridge/pkg/writer
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/nar-bridge/pkg/writer')
-rw-r--r--tvix/nar-bridge/pkg/writer/writer.go27
-rw-r--r--tvix/nar-bridge/pkg/writer/writer_pick_next_node_test.go20
-rw-r--r--tvix/nar-bridge/pkg/writer/writer_test.go41
3 files changed, 45 insertions, 43 deletions
diff --git a/tvix/nar-bridge/pkg/writer/writer.go b/tvix/nar-bridge/pkg/writer/writer.go
index e69cf27f2a50..fd154e061bf0 100644
--- a/tvix/nar-bridge/pkg/writer/writer.go
+++ b/tvix/nar-bridge/pkg/writer/writer.go
@@ -5,11 +5,12 @@ import (
 	"io"
 	"path"
 
+	castorev1pb "code.tvl.fyi/tvix/castore/protos"
 	storev1pb "code.tvl.fyi/tvix/store/protos"
 	"github.com/nix-community/go-nix/pkg/nar"
 )
 
-type DirectoryLookupFn func([]byte) (*storev1pb.Directory, error)
+type DirectoryLookupFn func([]byte) (*castorev1pb.Directory, error)
 type BlobLookupFn func([]byte) (io.ReadCloser, error)
 
 // Export will traverse a given pathInfo structure, and write the contents
@@ -38,13 +39,13 @@ func Export(
 	// and emit individual elements to the NAR writer, draining the Directory object.
 	// once it's empty, we can pop it off the stack.
 	var stackPaths = []string{}
-	var stackDirectories = []*storev1pb.Directory{}
+	var stackDirectories = []*castorev1pb.Directory{}
 
 	// peek at the pathInfo root and assemble the root node and write to writer
 	// in the case of a regular file, we retrieve and write the contents, close and exit
 	// in the case of a symlink, we write the symlink, close and exit
 	switch v := (pathInfo.GetNode().GetNode()).(type) {
-	case *storev1pb.Node_File:
+	case *castorev1pb.Node_File:
 		rootHeader.Type = nar.TypeRegular
 		rootHeader.Size = int64(v.File.GetSize())
 		rootHeader.Executable = v.File.GetExecutable()
@@ -77,7 +78,7 @@ func Export(
 
 		return nil
 
-	case *storev1pb.Node_Symlink:
+	case *castorev1pb.Node_Symlink:
 		rootHeader.Type = nar.TypeSymlink
 		rootHeader.LinkTarget = string(v.Symlink.GetTarget())
 		err := narWriter.WriteHeader(rootHeader)
@@ -91,7 +92,7 @@ func Export(
 		}
 
 		return nil
-	case *storev1pb.Node_Directory:
+	case *castorev1pb.Node_Directory:
 		// We have a directory at the root, look it up and put in on the stack.
 		directory, err := directoryLookupFn(v.Directory.Digest)
 		if err != nil {
@@ -136,7 +137,7 @@ func Export(
 		}
 
 		switch n := (nextNode).(type) {
-		case *storev1pb.DirectoryNode:
+		case *castorev1pb.DirectoryNode:
 			err := narWriter.WriteHeader(&nar.Header{
 				Path: path.Join(topOfStackPath, string(n.GetName())),
 				Type: nar.TypeDirectory,
@@ -153,7 +154,7 @@ func Export(
 			// add to stack
 			stackDirectories = append(stackDirectories, d)
 			stackPaths = append(stackPaths, path.Join(topOfStackPath, string(n.GetName())))
-		case *storev1pb.FileNode:
+		case *castorev1pb.FileNode:
 			err := narWriter.WriteHeader(&nar.Header{
 				Path:       path.Join(topOfStackPath, string(n.GetName())),
 				Type:       nar.TypeRegular,
@@ -180,7 +181,7 @@ func Export(
 			if err != nil {
 				return fmt.Errorf("unable to close content reader: %w", err)
 			}
-		case *storev1pb.SymlinkNode:
+		case *castorev1pb.SymlinkNode:
 			err := narWriter.WriteHeader(&nar.Header{
 				Path:       path.Join(topOfStackPath, string(n.GetName())),
 				Type:       nar.TypeSymlink,
@@ -198,15 +199,15 @@ func Export(
 
 // drainNextNode will drain a directory message with one of its child nodes,
 // whichever comes first alphabetically.
-func drainNextNode(d *storev1pb.Directory) interface{} {
+func drainNextNode(d *castorev1pb.Directory) interface{} {
 	switch v := (smallestNode(d)).(type) {
-	case *storev1pb.DirectoryNode:
+	case *castorev1pb.DirectoryNode:
 		d.Directories = d.Directories[1:]
 		return v
-	case *storev1pb.FileNode:
+	case *castorev1pb.FileNode:
 		d.Files = d.Files[1:]
 		return v
-	case *storev1pb.SymlinkNode:
+	case *castorev1pb.SymlinkNode:
 		d.Symlinks = d.Symlinks[1:]
 		return v
 	case nil:
@@ -218,7 +219,7 @@ func drainNextNode(d *storev1pb.Directory) interface{} {
 
 // smallestNode will return the node from a directory message,
 // whichever comes first alphabetically.
-func smallestNode(d *storev1pb.Directory) interface{} {
+func smallestNode(d *castorev1pb.Directory) interface{} {
 	childDirectories := d.GetDirectories()
 	childFiles := d.GetFiles()
 	childSymlinks := d.GetSymlinks()
diff --git a/tvix/nar-bridge/pkg/writer/writer_pick_next_node_test.go b/tvix/nar-bridge/pkg/writer/writer_pick_next_node_test.go
index 3601e9fb5296..d69adca89cb7 100644
--- a/tvix/nar-bridge/pkg/writer/writer_pick_next_node_test.go
+++ b/tvix/nar-bridge/pkg/writer/writer_pick_next_node_test.go
@@ -3,7 +3,7 @@ package writer
 import (
 	"testing"
 
-	storev1pb "code.tvl.fyi/tvix/store/protos"
+	castorev1pb "code.tvl.fyi/tvix/castore/protos"
 	"github.com/google/go-cmp/cmp"
 	"github.com/stretchr/testify/require"
 	"google.golang.org/protobuf/testing/protocmp"
@@ -17,18 +17,18 @@ func requireProtoEq(t *testing.T, expected interface{}, actual interface{}) {
 
 func TestPopNextNode(t *testing.T) {
 	t.Run("empty directory", func(t *testing.T) {
-		d := &storev1pb.Directory{
-			Directories: []*storev1pb.DirectoryNode{},
-			Files:       []*storev1pb.FileNode{},
-			Symlinks:    []*storev1pb.SymlinkNode{},
+		d := &castorev1pb.Directory{
+			Directories: []*castorev1pb.DirectoryNode{},
+			Files:       []*castorev1pb.FileNode{},
+			Symlinks:    []*castorev1pb.SymlinkNode{},
 		}
 
 		n := drainNextNode(d)
 		require.Equal(t, nil, n)
 	})
 	t.Run("only directories", func(t *testing.T) {
-		ds := &storev1pb.Directory{
-			Directories: []*storev1pb.DirectoryNode{{
+		ds := &castorev1pb.Directory{
+			Directories: []*castorev1pb.DirectoryNode{{
 				Name:   []byte("a"),
 				Digest: []byte{},
 				Size:   0,
@@ -37,12 +37,12 @@ func TestPopNextNode(t *testing.T) {
 				Digest: []byte{},
 				Size:   0,
 			}},
-			Files:    []*storev1pb.FileNode{},
-			Symlinks: []*storev1pb.SymlinkNode{},
+			Files:    []*castorev1pb.FileNode{},
+			Symlinks: []*castorev1pb.SymlinkNode{},
 		}
 
 		n := drainNextNode(ds)
-		requireProtoEq(t, &storev1pb.DirectoryNode{
+		requireProtoEq(t, &castorev1pb.DirectoryNode{
 			Name:   []byte("a"),
 			Digest: []byte{},
 			Size:   0,
diff --git a/tvix/nar-bridge/pkg/writer/writer_test.go b/tvix/nar-bridge/pkg/writer/writer_test.go
index 5914e1792bcb..83ac717aa3d6 100644
--- a/tvix/nar-bridge/pkg/writer/writer_test.go
+++ b/tvix/nar-bridge/pkg/writer/writer_test.go
@@ -8,6 +8,7 @@ import (
 	"os"
 	"testing"
 
+	castorev1pb "code.tvl.fyi/tvix/castore/protos"
 	"code.tvl.fyi/tvix/nar-bridge/pkg/reader"
 	"code.tvl.fyi/tvix/nar-bridge/pkg/writer"
 	storev1pb "code.tvl.fyi/tvix/store/protos"
@@ -15,7 +16,7 @@ import (
 	"lukechampine.com/blake3"
 )
 
-func mustDigest(d *storev1pb.Directory) []byte {
+func mustDigest(d *castorev1pb.Directory) []byte {
 	dgst, err := d.Digest()
 	if err != nil {
 		panic(err)
@@ -26,9 +27,9 @@ func mustDigest(d *storev1pb.Directory) []byte {
 func TestSymlink(t *testing.T) {
 	pathInfo := &storev1pb.PathInfo{
 
-		Node: &storev1pb.Node{
-			Node: &storev1pb.Node_Symlink{
-				Symlink: &storev1pb.SymlinkNode{
+		Node: &castorev1pb.Node{
+			Node: &castorev1pb.Node_Symlink{
+				Symlink: &castorev1pb.SymlinkNode{
 					Name:   []byte("doesntmatter"),
 					Target: []byte("/nix/store/somewhereelse"),
 				},
@@ -38,7 +39,7 @@ func TestSymlink(t *testing.T) {
 
 	var buf bytes.Buffer
 
-	err := writer.Export(&buf, pathInfo, func([]byte) (*storev1pb.Directory, error) {
+	err := writer.Export(&buf, pathInfo, func([]byte) (*castorev1pb.Directory, error) {
 		panic("no directories expected")
 	}, func([]byte) (io.ReadCloser, error) {
 		panic("no files expected")
@@ -65,9 +66,9 @@ func TestRegular(t *testing.T) {
 	}
 
 	pathInfo := &storev1pb.PathInfo{
-		Node: &storev1pb.Node{
-			Node: &storev1pb.Node_File{
-				File: &storev1pb.FileNode{
+		Node: &castorev1pb.Node{
+			Node: &castorev1pb.Node_File{
+				File: &castorev1pb.FileNode{
 					Name:       []byte("doesntmatter"),
 					Digest:     BLAKE3_DIGEST_0X01,
 					Size:       1,
@@ -79,7 +80,7 @@ func TestRegular(t *testing.T) {
 
 	var buf bytes.Buffer
 
-	err := writer.Export(&buf, pathInfo, func([]byte) (*storev1pb.Directory, error) {
+	err := writer.Export(&buf, pathInfo, func([]byte) (*castorev1pb.Directory, error) {
 		panic("no directories expected")
 	}, func(blobRef []byte) (io.ReadCloser, error) {
 		if !bytes.Equal(blobRef, BLAKE3_DIGEST_0X01) {
@@ -102,17 +103,17 @@ func TestRegular(t *testing.T) {
 
 func TestEmptyDirectory(t *testing.T) {
 	// construct empty directory node this refers to
-	emptyDirectory := &storev1pb.Directory{
-		Directories: []*storev1pb.DirectoryNode{},
-		Files:       []*storev1pb.FileNode{},
-		Symlinks:    []*storev1pb.SymlinkNode{},
+	emptyDirectory := &castorev1pb.Directory{
+		Directories: []*castorev1pb.DirectoryNode{},
+		Files:       []*castorev1pb.FileNode{},
+		Symlinks:    []*castorev1pb.SymlinkNode{},
 	}
 	emptyDirectoryDigest := mustDigest(emptyDirectory)
 
 	pathInfo := &storev1pb.PathInfo{
-		Node: &storev1pb.Node{
-			Node: &storev1pb.Node_Directory{
-				Directory: &storev1pb.DirectoryNode{
+		Node: &castorev1pb.Node{
+			Node: &castorev1pb.Node_Directory{
+				Directory: &castorev1pb.DirectoryNode{
 					Name:   []byte("doesntmatter"),
 					Digest: emptyDirectoryDigest,
 					Size:   0,
@@ -123,7 +124,7 @@ func TestEmptyDirectory(t *testing.T) {
 
 	var buf bytes.Buffer
 
-	err := writer.Export(&buf, pathInfo, func(directoryRef []byte) (*storev1pb.Directory, error) {
+	err := writer.Export(&buf, pathInfo, func(directoryRef []byte) (*castorev1pb.Directory, error) {
 		if !bytes.Equal(directoryRef, emptyDirectoryDigest) {
 			panic("unexpected directoryRef")
 		}
@@ -156,7 +157,7 @@ func TestFull(t *testing.T) {
 	require.NoError(t, err)
 
 	filesMap := make(map[string][]byte, 0)
-	directoriesMap := make(map[string]*storev1pb.Directory)
+	directoriesMap := make(map[string]*castorev1pb.Directory)
 
 	r := reader.New(bytes.NewBuffer(narContents))
 	pathInfo, err := r.Import(
@@ -174,7 +175,7 @@ func TestFull(t *testing.T) {
 
 			return nil
 		},
-		func(directory *storev1pb.Directory) error {
+		func(directory *castorev1pb.Directory) error {
 			dgst := mustDigest(directory)
 
 			directoriesMap[hex.EncodeToString(dgst)] = directory
@@ -190,7 +191,7 @@ func TestFull(t *testing.T) {
 	err = writer.Export(
 		&buf,
 		pathInfo,
-		func(directoryRef []byte) (*storev1pb.Directory, error) {
+		func(directoryRef []byte) (*castorev1pb.Directory, error) {
 			d, found := directoriesMap[hex.EncodeToString(directoryRef)]
 			if !found {
 				panic("directories not found")