mirror of
https://github.com/restic/restic.git
synced 2025-12-02 13:52:02 +00:00
add proper constants for node type
This commit is contained in:
@@ -59,7 +59,7 @@ func unwrapCtxCanceled(err error) error {
|
||||
// replaceSpecialNodes replaces nodes with name "." and "/" by their contents.
|
||||
// Otherwise, the node is returned.
|
||||
func replaceSpecialNodes(ctx context.Context, repo restic.BlobLoader, node *restic.Node) ([]*restic.Node, error) {
|
||||
if node.Type != "dir" || node.Subtree == nil {
|
||||
if node.Type != restic.NodeTypeDir || node.Subtree == nil {
|
||||
return []*restic.Node{node}, nil
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ func (d *dir) calcNumberOfLinks() uint32 {
|
||||
// of directories contained by d
|
||||
count := uint32(2)
|
||||
for _, node := range d.items {
|
||||
if node.Type == "dir" {
|
||||
if node.Type == restic.NodeTypeDir {
|
||||
count++
|
||||
}
|
||||
}
|
||||
@@ -182,11 +182,11 @@ func (d *dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
||||
name := cleanupNodeName(node.Name)
|
||||
var typ fuse.DirentType
|
||||
switch node.Type {
|
||||
case "dir":
|
||||
case restic.NodeTypeDir:
|
||||
typ = fuse.DT_Dir
|
||||
case "file":
|
||||
case restic.NodeTypeFile:
|
||||
typ = fuse.DT_File
|
||||
case "symlink":
|
||||
case restic.NodeTypeSymlink:
|
||||
typ = fuse.DT_Link
|
||||
}
|
||||
|
||||
@@ -215,13 +215,13 @@ func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
||||
}
|
||||
inode := inodeFromNode(d.inode, node)
|
||||
switch node.Type {
|
||||
case "dir":
|
||||
case restic.NodeTypeDir:
|
||||
return newDir(d.root, inode, d.inode, node)
|
||||
case "file":
|
||||
case restic.NodeTypeFile:
|
||||
return newFile(d.root, inode, node)
|
||||
case "symlink":
|
||||
case restic.NodeTypeSymlink:
|
||||
return newLink(d.root, inode, node)
|
||||
case "dev", "chardev", "fifo", "socket":
|
||||
case restic.NodeTypeDev, restic.NodeTypeCharDev, restic.NodeTypeFifo, restic.NodeTypeSocket:
|
||||
return newOther(d.root, inode, node)
|
||||
default:
|
||||
debug.Log(" node %v has unknown type %v", name, node.Type)
|
||||
|
||||
@@ -249,7 +249,7 @@ func TestBlocks(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInodeFromNode(t *testing.T) {
|
||||
node := &restic.Node{Name: "foo.txt", Type: "chardev", Links: 2}
|
||||
node := &restic.Node{Name: "foo.txt", Type: restic.NodeTypeCharDev, Links: 2}
|
||||
ino1 := inodeFromNode(1, node)
|
||||
ino2 := inodeFromNode(2, node)
|
||||
rtest.Assert(t, ino1 == ino2, "inodes %d, %d of hard links differ", ino1, ino2)
|
||||
@@ -261,9 +261,9 @@ func TestInodeFromNode(t *testing.T) {
|
||||
|
||||
// Regression test: in a path a/b/b, the grandchild should not get the
|
||||
// same inode as the grandparent.
|
||||
a := &restic.Node{Name: "a", Type: "dir", Links: 2}
|
||||
ab := &restic.Node{Name: "b", Type: "dir", Links: 2}
|
||||
abb := &restic.Node{Name: "b", Type: "dir", Links: 2}
|
||||
a := &restic.Node{Name: "a", Type: restic.NodeTypeDir, Links: 2}
|
||||
ab := &restic.Node{Name: "b", Type: restic.NodeTypeDir, Links: 2}
|
||||
abb := &restic.Node{Name: "b", Type: restic.NodeTypeDir, Links: 2}
|
||||
inoA := inodeFromNode(1, a)
|
||||
inoAb := inodeFromNode(inoA, ab)
|
||||
inoAbb := inodeFromNode(inoAb, abb)
|
||||
@@ -272,7 +272,7 @@ func TestInodeFromNode(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLink(t *testing.T) {
|
||||
node := &restic.Node{Name: "foo.txt", Type: "symlink", Links: 1, LinkTarget: "dst", ExtendedAttributes: []restic.ExtendedAttribute{
|
||||
node := &restic.Node{Name: "foo.txt", Type: restic.NodeTypeSymlink, Links: 1, LinkTarget: "dst", ExtendedAttributes: []restic.ExtendedAttribute{
|
||||
{Name: "foo", Value: []byte("bar")},
|
||||
}}
|
||||
|
||||
@@ -305,11 +305,11 @@ func BenchmarkInode(b *testing.B) {
|
||||
}{
|
||||
{
|
||||
name: "no_hard_links",
|
||||
node: restic.Node{Name: "a somewhat long-ish filename.svg.bz2", Type: "fifo"},
|
||||
node: restic.Node{Name: "a somewhat long-ish filename.svg.bz2", Type: restic.NodeTypeFifo},
|
||||
},
|
||||
{
|
||||
name: "hard_link",
|
||||
node: restic.Node{Name: "some other filename", Type: "file", Links: 2},
|
||||
node: restic.Node{Name: "some other filename", Type: restic.NodeTypeFile, Links: 2},
|
||||
},
|
||||
} {
|
||||
b.Run(sub.name, func(b *testing.B) {
|
||||
|
||||
@@ -25,7 +25,7 @@ func inodeFromName(parent uint64, name string) uint64 {
|
||||
|
||||
// inodeFromNode generates an inode number for a file within a snapshot.
|
||||
func inodeFromNode(parent uint64, node *restic.Node) (inode uint64) {
|
||||
if node.Links > 1 && node.Type != "dir" {
|
||||
if node.Links > 1 && node.Type != restic.NodeTypeDir {
|
||||
// If node has hard links, give them all the same inode,
|
||||
// irrespective of the parent.
|
||||
var buf [16]byte
|
||||
|
||||
Reference in New Issue
Block a user