Skip to content

Commit 6ddb0bd

Browse files
authored
Merge pull request #2103 from dmcgowan/backport-1.0-2095
[release/1.0] archive: fixes missing whiteout parent directories
2 parents 7193749 + bed74e2 commit 6ddb0bd

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

archive/tar.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ func (cw *changeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
332332
AccessTime: cw.whiteoutT,
333333
ChangeTime: cw.whiteoutT,
334334
}
335+
if err := cw.includeParents(hdr); err != nil {
336+
return err
337+
}
335338
if err := cw.tw.WriteHeader(hdr); err != nil {
336339
return errors.Wrap(err, "failed to write whiteout header")
337340
}

archive/tar_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ func TestDiffTar(t *testing.T) {
874874
fileEntry("d3/l1", []byte("link me"), 0644),
875875
dirEntry("d4/", 0755),
876876
linkEntry("d4/f1", "d3/l1"),
877+
dirEntry("d6/", 0755),
877878
whiteoutEntry("d6/l1"),
878879
whiteoutEntry("d6/l2"),
879880
},
@@ -947,6 +948,46 @@ func TestDiffTar(t *testing.T) {
947948
fstest.Link("/d3/f1", "/d4/l1"),
948949
),
949950
},
951+
{
952+
name: "WhiteoutIncludesParents",
953+
validators: []tarEntryValidator{
954+
dirEntry("d1/", 0755),
955+
whiteoutEntry("d1/f1"),
956+
dirEntry("d2/", 0755),
957+
whiteoutEntry("d2/f1"),
958+
fileEntry("d2/f2", []byte("content"), 0777),
959+
dirEntry("d3/", 0755),
960+
whiteoutEntry("d3/f1"),
961+
fileEntry("d3/f2", []byte("content"), 0644),
962+
dirEntry("d4/", 0755),
963+
fileEntry("d4/f0", []byte("content"), 0644),
964+
whiteoutEntry("d4/f1"),
965+
whiteoutEntry("d5"),
966+
},
967+
a: fstest.Apply(
968+
fstest.CreateDir("/d1/", 0755),
969+
fstest.CreateFile("/d1/f1", []byte("content"), 0644),
970+
fstest.CreateDir("/d2/", 0755),
971+
fstest.CreateFile("/d2/f1", []byte("content"), 0644),
972+
fstest.CreateFile("/d2/f2", []byte("content"), 0644),
973+
fstest.CreateDir("/d3/", 0755),
974+
fstest.CreateFile("/d3/f1", []byte("content"), 0644),
975+
fstest.CreateDir("/d4/", 0755),
976+
fstest.CreateFile("/d4/f1", []byte("content"), 0644),
977+
fstest.CreateDir("/d5/", 0755),
978+
fstest.CreateFile("/d5/f1", []byte("content"), 0644),
979+
),
980+
b: fstest.Apply(
981+
fstest.Remove("/d1/f1"),
982+
fstest.Remove("/d2/f1"),
983+
fstest.Chmod("/d2/f2", 0777),
984+
fstest.Remove("/d3/f1"),
985+
fstest.CreateFile("/d3/f2", []byte("content"), 0644),
986+
fstest.Remove("/d4/f1"),
987+
fstest.CreateFile("/d4/f0", []byte("content"), 0644),
988+
fstest.RemoveAll("/d5"),
989+
),
990+
},
950991
}
951992

952993
for _, at := range tests {

0 commit comments

Comments
 (0)