feat(tvix/castore): add RenamedNode helper
This takes a castorev1pb.Node and updates its name, making sure to copy it. Change-Id: I57bf2b2b4a74496a1a697bcbce72bf67a12e69fe Reviewed-on: https://cl.tvl.fyi/c/depot/+/9594 Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Reviewed-by: Brian McGee <brian@bmcgee.ie>
This commit is contained in:
parent
78abeaa920
commit
abf9c05090
1 changed files with 38 additions and 0 deletions
38
tvix/castore/protos/rename_node.go
Normal file
38
tvix/castore/protos/rename_node.go
Normal file
|
@ -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")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue