mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #23912 from dmcgowan/fix-overlay2-whiteout-exclusion
Fix overlay2 ignoring whiteout files
This commit is contained in:
commit
37fe4bdb59
4 changed files with 48 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue