mirror of https://github.com/docker/docs.git
ApplyLayer: Fix TestLookupImage
The TestLookupImage test seems to use a layer that contains /etc/postgres/postgres.conf, but not e.g. /etc/postgres. To handle this we ensure that the parent directory always exists, and if not we create it.
This commit is contained in:
parent
a8af12f80a
commit
78c22c24b3
|
@ -49,6 +49,23 @@ func ApplyLayer(dest string, layer Archive) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normalize name, for safety and for a simple is-root check
|
||||||
|
hdr.Name = filepath.Clean(hdr.Name)
|
||||||
|
|
||||||
|
if !strings.HasSuffix(hdr.Name, "/") {
|
||||||
|
// Not the root directory, ensure that the parent directory exists
|
||||||
|
// This happened in some tests where an image had a tarfile without any
|
||||||
|
// parent directories
|
||||||
|
parent := filepath.Dir(hdr.Name)
|
||||||
|
parentPath := filepath.Join(dest, parent)
|
||||||
|
if _, err := os.Lstat(parentPath); err != nil && os.IsNotExist(err) {
|
||||||
|
err = os.MkdirAll(parentPath, 600)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Skip AUFS metadata dirs
|
// Skip AUFS metadata dirs
|
||||||
if strings.HasPrefix(hdr.Name, ".wh..wh.") {
|
if strings.HasPrefix(hdr.Name, ".wh..wh.") {
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue