about summary refs log tree commit diff
path: root/tvix/castore-go/rename_node.go
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/castore-go/rename_node.go')
-rw-r--r--tvix/castore-go/rename_node.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/tvix/castore-go/rename_node.go b/tvix/castore-go/rename_node.go
new file mode 100644
index 000000000000..80537b16d38d
--- /dev/null
+++ b/tvix/castore-go/rename_node.go
@@ -0,0 +1,38 @@
+package castorev1
+
+// RenamedNode returns a node with a new name.
+func RenamedNode(node *Node, name string) *Node {
+	if directoryNode := node.GetDirectory(); directoryNode != nil {
+		return &Node{
+			Node: &Node_Directory{
+				Directory: &DirectoryNode{
+					Name:   []byte(name),
+					Digest: directoryNode.GetDigest(),
+					Size:   directoryNode.GetSize(),
+				},
+			},
+		}
+	} else if fileNode := node.GetFile(); fileNode != nil {
+		return &Node{
+			Node: &Node_File{
+				File: &FileNode{
+					Name:       []byte(name),
+					Digest:     fileNode.GetDigest(),
+					Size:       fileNode.GetSize(),
+					Executable: fileNode.GetExecutable(),
+				},
+			},
+		}
+	} else if symlinkNode := node.GetSymlink(); symlinkNode != nil {
+		return &Node{
+			Node: &Node_Symlink{
+				Symlink: &SymlinkNode{
+					Name:   []byte(name),
+					Target: symlinkNode.GetTarget(),
+				},
+			},
+		}
+	} else {
+		panic("unreachable")
+	}
+}