Skip to content

Commit 84dc165

Browse files
committed
Ensure rmdir gets set for every directory
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 <[email protected]>
1 parent a8bf017 commit 84dc165

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

fs/diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func doubleWalkDiff(ctx context.Context, changeFn ChangeFunc, a, b string) (err
273273
if rmdir != "" && strings.HasPrefix(f1.path, rmdir) {
274274
f1 = nil
275275
continue
276-
} else if rmdir == "" && f1.f.IsDir() {
276+
} else if f1.f.IsDir() {
277277
rmdir = f1.path + string(os.PathSeparator)
278278
} else if rmdir != "" {
279279
rmdir = ""

fs/diff_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ func TestSimpleDiff(t *testing.T) {
5656
}
5757
}
5858

59+
func TestNestedDeletion(t *testing.T) {
60+
skipDiffTestOnWindows(t)
61+
l1 := fstest.Apply(
62+
fstest.CreateDir("/d0", 0755),
63+
fstest.CreateDir("/d1", 0755),
64+
fstest.CreateDir("/d1/d2", 0755),
65+
fstest.CreateFile("/d1/d2/f1", []byte("mydomain 10.0.0.1"), 0644),
66+
)
67+
l2 := fstest.Apply(
68+
fstest.RemoveAll("/d0"),
69+
fstest.RemoveAll("/d1"),
70+
)
71+
diff := []TestChange{
72+
Delete("/d0"),
73+
Delete("/d1"),
74+
}
75+
76+
if err := testDiffWithBase(l1, l2, diff); err != nil {
77+
t.Fatalf("Failed diff with base: %+v", err)
78+
}
79+
}
80+
5981
func TestDirectoryReplace(t *testing.T) {
6082
skipDiffTestOnWindows(t)
6183
l1 := fstest.Apply(

0 commit comments

Comments
 (0)