mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add basic support for .wh..wh..opq
This fixes the case where directory is removed in aufs and then the same layer is imported to a different graphdriver. Currently when you do `rm -rf /foo && mkdir /foo` in a layer in aufs the files under `foo` would only be be hidden on aufs. The problems with this fix: 1) When a new diff is recreated from non-aufs driver the `opq` files would not be there. This should not mean layer differences for the user but still different content in the tar (one would have one `opq` file, the others would have `.wh.*` for every file inside that folder). This difference also only happens if the tar-split file isn’t stored for the layer. 2) New files that have the filenames before `.wh..wh..opq` when they are sorted do not get picked up by non-aufs graphdrivers. Fixing this would require a bigger refactoring that is planned in the future. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
985b7ec895
commit
00e3277107
2 changed files with 22 additions and 5 deletions
|
@ -322,7 +322,7 @@ func (a *Driver) Diff(id, parent string) (archive.Archive, error) {
|
|||
// AUFS doesn't need the parent layer to produce a diff.
|
||||
return archive.TarWithOptions(path.Join(a.rootPath(), "diff", id), &archive.TarOptions{
|
||||
Compression: archive.Uncompressed,
|
||||
ExcludePatterns: []string{".wh..wh.*"},
|
||||
ExcludePatterns: []string{".wh..wh.*", "!.wh..wh..opq"},
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,10 @@ func UnpackLayer(dest string, layer Reader) (size int64, err error) {
|
|||
return 0, err
|
||||
}
|
||||
}
|
||||
continue
|
||||
|
||||
if hdr.Name != ".wh..wh..opq" {
|
||||
continue
|
||||
}
|
||||
}
|
||||
path := filepath.Join(dest, hdr.Name)
|
||||
rel, err := filepath.Rel(dest, path)
|
||||
|
@ -116,9 +119,23 @@ func UnpackLayer(dest string, layer Reader) (size int64, err error) {
|
|||
|
||||
if strings.HasPrefix(base, ".wh.") {
|
||||
originalBase := base[len(".wh."):]
|
||||
originalPath := filepath.Join(filepath.Dir(path), originalBase)
|
||||
if err := os.RemoveAll(originalPath); err != nil {
|
||||
return 0, err
|
||||
dir := filepath.Dir(path)
|
||||
if originalBase == ".wh..opq" {
|
||||
fi, err := os.Lstat(dir)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return 0, err
|
||||
}
|
||||
if err := os.RemoveAll(dir); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if err := os.Mkdir(dir, fi.Mode()&os.ModePerm); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
} else {
|
||||
originalPath := filepath.Join(dir, originalBase)
|
||||
if err := os.RemoveAll(originalPath); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If path exits we almost always just want to remove and replace it.
|
||||
|
|
Loading…
Reference in a new issue