diff --git a/archive/tar.go b/archive/tar.go index fca4a38a3..fd6c07206 100644 --- a/archive/tar.go +++ b/archive/tar.go @@ -436,6 +436,9 @@ func (cw *changeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e AccessTime: cw.whiteoutT, ChangeTime: cw.whiteoutT, } + if err := cw.includeParents(hdr); err != nil { + return err + } if err := cw.tw.WriteHeader(hdr); err != nil { return errors.Wrap(err, "failed to write whiteout header") } diff --git a/archive/tar_test.go b/archive/tar_test.go index ae1ce961a..a6cd0db17 100644 --- a/archive/tar_test.go +++ b/archive/tar_test.go @@ -874,6 +874,7 @@ func TestDiffTar(t *testing.T) { fileEntry("d3/l1", []byte("link me"), 0644), dirEntry("d4/", 0755), linkEntry("d4/f1", "d3/l1"), + dirEntry("d6/", 0755), whiteoutEntry("d6/l1"), whiteoutEntry("d6/l2"), }, @@ -947,6 +948,46 @@ func TestDiffTar(t *testing.T) { fstest.Link("/d3/f1", "/d4/l1"), ), }, + { + name: "WhiteoutIncludesParents", + validators: []tarEntryValidator{ + dirEntry("d1/", 0755), + whiteoutEntry("d1/f1"), + dirEntry("d2/", 0755), + whiteoutEntry("d2/f1"), + fileEntry("d2/f2", []byte("content"), 0777), + dirEntry("d3/", 0755), + whiteoutEntry("d3/f1"), + fileEntry("d3/f2", []byte("content"), 0644), + dirEntry("d4/", 0755), + fileEntry("d4/f0", []byte("content"), 0644), + whiteoutEntry("d4/f1"), + whiteoutEntry("d5"), + }, + a: fstest.Apply( + fstest.CreateDir("/d1/", 0755), + fstest.CreateFile("/d1/f1", []byte("content"), 0644), + fstest.CreateDir("/d2/", 0755), + fstest.CreateFile("/d2/f1", []byte("content"), 0644), + fstest.CreateFile("/d2/f2", []byte("content"), 0644), + fstest.CreateDir("/d3/", 0755), + fstest.CreateFile("/d3/f1", []byte("content"), 0644), + fstest.CreateDir("/d4/", 0755), + fstest.CreateFile("/d4/f1", []byte("content"), 0644), + fstest.CreateDir("/d5/", 0755), + fstest.CreateFile("/d5/f1", []byte("content"), 0644), + ), + b: fstest.Apply( + fstest.Remove("/d1/f1"), + fstest.Remove("/d2/f1"), + fstest.Chmod("/d2/f2", 0777), + fstest.Remove("/d3/f1"), + fstest.CreateFile("/d3/f2", []byte("content"), 0644), + fstest.Remove("/d4/f1"), + fstest.CreateFile("/d4/f0", []byte("content"), 0644), + fstest.RemoveAll("/d5"), + ), + }, } for _, at := range tests {