Skip to content

Commit

Permalink
ApplyLayer: Fix TestLookupImage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexlarsson committed Dec 16, 2013
1 parent a8af12f commit 78c22c2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions archive/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ func ApplyLayer(dest string, layer Archive) error {
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
if strings.HasPrefix(hdr.Name, ".wh..wh.") {
continue
Expand Down

0 comments on commit 78c22c2

Please sign in to comment.