Skip to content
Permalink
Browse files

fs: in RmChild, remove parent backlink from child

Add posix.LinkUnlinkRename to test this behavior; this is the approach
that git uses for writing pack files.

Thanks to Nicola Girardi <idrarig.alocin@gmail.com> for reporting this
bug.

Change-Id: Idb34e32f1dbb3c6c617aa82e29c4f0ac6f8a544d
  • Loading branch information...
hanwen committed Oct 4, 2019
1 parent aaec731 commit 1266c0dcb6edad0f68613398974b339ea18cec5d
Showing with 26 additions and 0 deletions.
  1. +2 −0 fs/inode.go
  2. +24 −0 posixtest/test.go
@@ -545,6 +545,8 @@ retry:
for _, nm := range names {
ch := n.children[nm]
delete(n.children, nm)
delete(ch.parents, parentData{nm, n})

ch.changeCounter++
}
n.changeCounter++
@@ -29,6 +29,7 @@ var All = map[string]func(*testing.T, string){
"NlinkZero": NlinkZero,
"ParallelFileOpen": ParallelFileOpen,
"Link": Link,
"LinkUnlinkRename": LinkUnlinkRename,
"RenameOverwriteDestNoExist": RenameOverwriteDestNoExist,
"RenameOverwriteDestExist": RenameOverwriteDestExist,
"ReadDir": ReadDir,
@@ -347,3 +348,26 @@ func ReadDir(t *testing.T, mnt string) {
}
}
}

// LinkUnlinkRename implements rename with a link/unlink sequence
func LinkUnlinkRename(t *testing.T, mnt string) {
content := []byte("hello")
tmp := mnt + "/tmpfile"
if err := ioutil.WriteFile(tmp, content, 0644); err != nil {
t.Fatalf("WriteFile %q: %v", tmp, err)
}

dest := mnt + "/file"
if err := syscall.Link(tmp, dest); err != nil {
t.Fatalf("Link %q %q: %v", tmp, dest, err)
}
if err := syscall.Unlink(tmp); err != nil {
t.Fatalf("Unlink %q: %v", tmp, err)
}

if back, err := ioutil.ReadFile(dest); err != nil {
t.Fatalf("Read %q: %v", dest, err)
} else if bytes.Compare(back, content) != 0 {
t.Fatalf("Read got %q want %q", back, content)
}
}

0 comments on commit 1266c0d

Please sign in to comment.
You can’t perform that action at this time.