Skip to content

Commit

Permalink
Ensure rmdir gets set for every directory
Browse files Browse the repository at this point in the history
Fixes a bug where rmdir was not getting set on a directory if the
previous change was also a directory.

From f3fdbe586829c02f81fc55da62618b5a2b0edc51 in containerd/continuity

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
  • Loading branch information
dmcgowan committed Feb 12, 2018
1 parent a8bf017 commit 84dc165
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fs/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func doubleWalkDiff(ctx context.Context, changeFn ChangeFunc, a, b string) (err
if rmdir != "" && strings.HasPrefix(f1.path, rmdir) {
f1 = nil
continue
} else if rmdir == "" && f1.f.IsDir() {
} else if f1.f.IsDir() {
rmdir = f1.path + string(os.PathSeparator)
} else if rmdir != "" {
rmdir = ""
Expand Down
22 changes: 22 additions & 0 deletions fs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ func TestSimpleDiff(t *testing.T) {
}
}

func TestNestedDeletion(t *testing.T) {
skipDiffTestOnWindows(t)
l1 := fstest.Apply(
fstest.CreateDir("/d0", 0755),
fstest.CreateDir("/d1", 0755),
fstest.CreateDir("/d1/d2", 0755),
fstest.CreateFile("/d1/d2/f1", []byte("mydomain 10.0.0.1"), 0644),
)
l2 := fstest.Apply(
fstest.RemoveAll("/d0"),
fstest.RemoveAll("/d1"),
)
diff := []TestChange{
Delete("/d0"),
Delete("/d1"),
}

if err := testDiffWithBase(l1, l2, diff); err != nil {
t.Fatalf("Failed diff with base: %+v", err)
}
}

func TestDirectoryReplace(t *testing.T) {
skipDiffTestOnWindows(t)
l1 := fstest.Apply(
Expand Down

0 comments on commit 84dc165

Please sign in to comment.