Skip to content

Commit b99bbe9

Browse files
authored
Merge pull request #2127 from dmcgowan/cherry-pick-2119
[release/1.0] archive/diff: fix consecutive directory removal bug
2 parents 53aaa89 + 84dc165 commit b99bbe9

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

archive/tar_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,24 @@ func TestDiffTar(t *testing.T) {
988988
fstest.RemoveAll("/d5"),
989989
),
990990
},
991+
{
992+
name: "WhiteoutParentRemoval",
993+
validators: []tarEntryValidator{
994+
whiteoutEntry("d1"),
995+
whiteoutEntry("d2"),
996+
dirEntry("d3/", 0755),
997+
},
998+
a: fstest.Apply(
999+
fstest.CreateDir("/d1/", 0755),
1000+
fstest.CreateDir("/d2/", 0755),
1001+
fstest.CreateFile("/d2/f1", []byte("content"), 0644),
1002+
),
1003+
b: fstest.Apply(
1004+
fstest.RemoveAll("/d1"),
1005+
fstest.RemoveAll("/d2"),
1006+
fstest.CreateDir("/d3/", 0755),
1007+
),
1008+
},
9911009
}
9921010

9931011
for _, at := range tests {

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)