diff --git a/daemon/graphdriver/graphtest/graphtest_unix.go b/daemon/graphdriver/graphtest/graphtest_unix.go index 4762c85556..b83fb13e3e 100644 --- a/daemon/graphdriver/graphtest/graphtest_unix.go +++ b/daemon/graphdriver/graphtest/graphtest_unix.go @@ -197,6 +197,8 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO defer PutDriver(t) base := stringid.GenerateRandomID() upper := stringid.GenerateRandomID() + deleteFile := "file-remove.txt" + deleteFileContent := []byte("This file should get removed in upper!") if err := driver.Create(base, "", "", nil); err != nil { t.Fatal(err) @@ -206,6 +208,10 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO t.Fatal(err) } + if err := addFile(driver, base, deleteFile, deleteFileContent); err != nil { + t.Fatal(err) + } + if err := driver.Create(upper, base, "", nil); err != nil { t.Fatal(err) } @@ -213,6 +219,11 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO if err := addManyFiles(driver, upper, fileCount, 6); err != nil { t.Fatal(err) } + + if err := removeFile(driver, upper, deleteFile); err != nil { + t.Fatal(err) + } + diffSize, err := driver.DiffSize(upper, "") if err != nil { t.Fatal(err) @@ -227,6 +238,10 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO t.Fatal(err) } + if err := checkFile(driver, diff, deleteFile, deleteFileContent); err != nil { + t.Fatal(err) + } + arch, err := driver.Diff(upper, base) if err != nil { t.Fatal(err) @@ -248,9 +263,14 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO if applyDiffSize != diffSize { t.Fatalf("Apply diff size different, got %d, expected %d", applyDiffSize, diffSize) } + if err := checkManyFiles(driver, diff, fileCount, 6); err != nil { t.Fatal(err) } + + if err := checkFileRemoved(driver, diff, deleteFile); err != nil { + t.Fatal(err) + } } // DriverTestChanges tests computed changes on a layer matches changes made diff --git a/daemon/graphdriver/graphtest/testutil.go b/daemon/graphdriver/graphtest/testutil.go index 5917d0dac4..dc3585751a 100644 --- a/daemon/graphdriver/graphtest/testutil.go +++ b/daemon/graphdriver/graphtest/testutil.go @@ -78,6 +78,32 @@ func addFile(drv graphdriver.Driver, layer, filename string, content []byte) err return ioutil.WriteFile(path.Join(root, filename), content, 0755) } +func removeFile(drv graphdriver.Driver, layer, filename string) error { + root, err := drv.Get(layer, "") + if err != nil { + return err + } + defer drv.Put(layer) + + return os.Remove(path.Join(root, filename)) +} + +func checkFileRemoved(drv graphdriver.Driver, layer, filename string) error { + root, err := drv.Get(layer, "") + if err != nil { + return err + } + defer drv.Put(layer) + + if _, err := os.Stat(path.Join(root, filename)); err == nil { + return fmt.Errorf("file still exists: %s", path.Join(root, filename)) + } else if !os.IsNotExist(err) { + return err + } + + return nil +} + func addManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) error { root, err := drv.Get(layer, "") if err != nil { diff --git a/pkg/archive/archive.go b/pkg/archive/archive.go index 4f0b4ffefe..aec3b393de 100644 --- a/pkg/archive/archive.go +++ b/pkg/archive/archive.go @@ -359,7 +359,7 @@ func (ta *tarAppender) addTarFile(path, name string) error { return err } - if hdr.Typeflag == tar.TypeReg { + if hdr.Typeflag == tar.TypeReg && hdr.Size > 0 { file, err := os.Open(path) if err != nil { return err diff --git a/pkg/archive/archive_linux.go b/pkg/archive/archive_linux.go index 86d2c7fe34..277ff98885 100644 --- a/pkg/archive/archive_linux.go +++ b/pkg/archive/archive_linux.go @@ -26,6 +26,7 @@ func (overlayWhiteoutConverter) ConvertWrite(hdr *tar.Header, path string, fi os hdr.Name = WhiteoutPrefix + hdr.Name hdr.Mode = 0600 hdr.Typeflag = tar.TypeReg + hdr.Size = 0 } if fi.Mode()&os.ModeDir != 0 {