Commit 1266c0dc authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

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
parent aaec7316
...@@ -545,6 +545,8 @@ retry: ...@@ -545,6 +545,8 @@ retry:
for _, nm := range names { for _, nm := range names {
ch := n.children[nm] ch := n.children[nm]
delete(n.children, nm) delete(n.children, nm)
delete(ch.parents, parentData{nm, n})
ch.changeCounter++ ch.changeCounter++
} }
n.changeCounter++ n.changeCounter++
......
...@@ -29,6 +29,7 @@ var All = map[string]func(*testing.T, string){ ...@@ -29,6 +29,7 @@ var All = map[string]func(*testing.T, string){
"NlinkZero": NlinkZero, "NlinkZero": NlinkZero,
"ParallelFileOpen": ParallelFileOpen, "ParallelFileOpen": ParallelFileOpen,
"Link": Link, "Link": Link,
"LinkUnlinkRename": LinkUnlinkRename,
"RenameOverwriteDestNoExist": RenameOverwriteDestNoExist, "RenameOverwriteDestNoExist": RenameOverwriteDestNoExist,
"RenameOverwriteDestExist": RenameOverwriteDestExist, "RenameOverwriteDestExist": RenameOverwriteDestExist,
"ReadDir": ReadDir, "ReadDir": ReadDir,
...@@ -347,3 +348,26 @@ func ReadDir(t *testing.T, mnt string) { ...@@ -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)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment