fix removing path from inode2path

This commit is contained in:
chrislu 2022-07-23 18:20:29 -07:00
parent 41eeb4deef
commit d24db396cc
2 changed files with 16 additions and 2 deletions

View file

@ -34,8 +34,8 @@ func (ie *InodeEntry) removeOnePath(p util.FullPath) bool {
if idx < 0 { if idx < 0 {
return false return false
} }
for x := len(ie.paths) - 2; x > idx; x-- { for x := idx; x < len(ie.paths)-1; x++ {
ie.paths[x-1] = ie.paths[x] ie.paths[x] = ie.paths[x+1]
} }
ie.paths = ie.paths[0 : len(ie.paths)-1] ie.paths = ie.paths[0 : len(ie.paths)-1]
return true return true

View file

@ -13,6 +13,15 @@ func TestInodeEntry_removeOnePath(t *testing.T) {
want bool want bool
count int count int
}{ }{
{
name: "actual case",
entry: InodeEntry{
paths: []util.FullPath{"/pjd/nx", "/pjd/n0"},
},
p: "/pjd/nx",
want: true,
count: 1,
},
{ {
name: "empty", name: "empty",
entry: InodeEntry{}, entry: InodeEntry{},
@ -74,6 +83,11 @@ func TestInodeEntry_removeOnePath(t *testing.T) {
if tt.count != len(tt.entry.paths) { if tt.count != len(tt.entry.paths) {
t.Errorf("removeOnePath path count = %v, want %v", len(tt.entry.paths), tt.count) t.Errorf("removeOnePath path count = %v, want %v", len(tt.entry.paths), tt.count)
} }
for i, p := range tt.entry.paths {
if p == tt.p {
t.Errorf("removeOnePath found path still exists at %v, %v", i, p)
}
}
}) })
} }
} }