Merge pull request #4255 from greatroar/fuse-hash

fuse: Mix inode hashes in a non-symmetric way
This commit is contained in:
Michael Eischer
2023-04-07 12:56:57 +02:00
committed by GitHub
3 changed files with 33 additions and 2 deletions

View File

@@ -258,6 +258,17 @@ func TestInodeFromNode(t *testing.T) {
ino1 = inodeFromNode(1, node)
ino2 = inodeFromNode(2, node)
rtest.Assert(t, ino1 != ino2, "same inode %d but different parent", ino1)
// 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}
inoA := inodeFromNode(1, a)
inoAb := inodeFromNode(inoA, ab)
inoAbb := inodeFromNode(inoAb, abb)
rtest.Assert(t, inoA != inoAb, "inode(a/b) = inode(a)")
rtest.Assert(t, inoA != inoAbb, "inode(a/b/b) = inode(a)")
}
var sink uint64

View File

@@ -10,9 +10,11 @@ import (
"github.com/restic/restic/internal/restic"
)
const prime = 11400714785074694791 // prime1 from xxhash.
// inodeFromName generates an inode number for a file in a meta dir.
func inodeFromName(parent uint64, name string) uint64 {
inode := parent ^ xxhash.Sum64String(cleanupNodeName(name))
inode := prime*parent ^ xxhash.Sum64String(cleanupNodeName(name))
// Inode 0 is invalid and 1 is the root. Remap those.
if inode < 2 {
@@ -33,7 +35,7 @@ func inodeFromNode(parent uint64, node *restic.Node) (inode uint64) {
} else {
// Else, use the name and the parent inode.
// node.{DeviceID,Inode} may not even be reliable.
inode = parent ^ xxhash.Sum64String(cleanupNodeName(node.Name))
inode = prime*parent ^ xxhash.Sum64String(cleanupNodeName(node.Name))
}
// Inode 0 is invalid and 1 is the root. Remap those.