1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix overlay2 ignoring whiteout files

Currently when overlay creates a whiteout file then the overlay2 layer is archived,
the correct tar header will be created for the whiteout file, but the tar logic will then attempt to open the file causing a failure.
When tar encounters such failures the file is skipped and excluded for the archive, causing the whiteout to be ignored.
By skipping the copy of empty files, no open attempt will be made on whiteout files.

Fixes #23863

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
Derek McGowan 2016-06-23 13:34:38 -07:00
parent 8f9c7fab24
commit bd13c53f8d
4 changed files with 48 additions and 1 deletions

View file

@ -197,6 +197,8 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO
defer PutDriver(t) defer PutDriver(t)
base := stringid.GenerateRandomID() base := stringid.GenerateRandomID()
upper := 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 { if err := driver.Create(base, "", "", nil); err != nil {
t.Fatal(err) t.Fatal(err)
@ -206,6 +208,10 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO
t.Fatal(err) t.Fatal(err)
} }
if err := addFile(driver, base, deleteFile, deleteFileContent); err != nil {
t.Fatal(err)
}
if err := driver.Create(upper, base, "", nil); err != nil { if err := driver.Create(upper, base, "", nil); err != nil {
t.Fatal(err) 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 { if err := addManyFiles(driver, upper, fileCount, 6); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := removeFile(driver, upper, deleteFile); err != nil {
t.Fatal(err)
}
diffSize, err := driver.DiffSize(upper, "") diffSize, err := driver.DiffSize(upper, "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -227,6 +238,10 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO
t.Fatal(err) t.Fatal(err)
} }
if err := checkFile(driver, diff, deleteFile, deleteFileContent); err != nil {
t.Fatal(err)
}
arch, err := driver.Diff(upper, base) arch, err := driver.Diff(upper, base)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -248,9 +263,14 @@ func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverO
if applyDiffSize != diffSize { if applyDiffSize != diffSize {
t.Fatalf("Apply diff size different, got %d, expected %d", applyDiffSize, diffSize) t.Fatalf("Apply diff size different, got %d, expected %d", applyDiffSize, diffSize)
} }
if err := checkManyFiles(driver, diff, fileCount, 6); err != nil { if err := checkManyFiles(driver, diff, fileCount, 6); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := checkFileRemoved(driver, diff, deleteFile); err != nil {
t.Fatal(err)
}
} }
// DriverTestChanges tests computed changes on a layer matches changes made // DriverTestChanges tests computed changes on a layer matches changes made

View file

@ -78,6 +78,32 @@ func addFile(drv graphdriver.Driver, layer, filename string, content []byte) err
return ioutil.WriteFile(path.Join(root, filename), content, 0755) 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 { func addManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) error {
root, err := drv.Get(layer, "") root, err := drv.Get(layer, "")
if err != nil { if err != nil {

View file

@ -359,7 +359,7 @@ func (ta *tarAppender) addTarFile(path, name string) error {
return err return err
} }
if hdr.Typeflag == tar.TypeReg { if hdr.Typeflag == tar.TypeReg && hdr.Size > 0 {
file, err := os.Open(path) file, err := os.Open(path)
if err != nil { if err != nil {
return err return err

View file

@ -26,6 +26,7 @@ func (overlayWhiteoutConverter) ConvertWrite(hdr *tar.Header, path string, fi os
hdr.Name = WhiteoutPrefix + hdr.Name hdr.Name = WhiteoutPrefix + hdr.Name
hdr.Mode = 0600 hdr.Mode = 0600
hdr.Typeflag = tar.TypeReg hdr.Typeflag = tar.TypeReg
hdr.Size = 0
} }
if fi.Mode()&os.ModeDir != 0 { if fi.Mode()&os.ModeDir != 0 {