diff --git a/pkg/stacker/import.go b/pkg/stacker/import.go index 67d8cd74..0fcb87c1 100644 --- a/pkg/stacker/import.go +++ b/pkg/stacker/import.go @@ -125,6 +125,7 @@ func importFile(imp string, cacheDir string, hash string, idest string, mode *fs } dest := path.Join(cacheDir, path.Base(imp)) + if err := os.MkdirAll(dest, 0755); err != nil { return "", errors.Wrapf(err, "failed making cache dir") } @@ -156,7 +157,12 @@ func importFile(imp string, cacheDir string, hash string, idest string, mode *fs fallthrough case mtree.Extra: srcpath := path.Join(imp, d.Path()) - destpath := path.Join(cacheDir, path.Base(imp), d.Path()) + var destpath string + if imp[len(imp)-1:] == "/" { + destpath = path.Join(cacheDir, d.Path()) + } else { + destpath = path.Join(cacheDir, path.Base(imp), d.Path()) + } if d.New().IsDir() { fi, err := os.Lstat(destpath) diff --git a/pkg/types/layer.go b/pkg/types/layer.go index ea597aa0..7be0cbf2 100644 --- a/pkg/types/layer.go +++ b/pkg/types/layer.go @@ -406,6 +406,9 @@ func (l Layer) absolutify(referenceDirectory string) (Layer, error) { if err != nil { return ret, err } + if rawImport.Path[len(rawImport.Path)-1:] == "/" { + absImportPath += "/" + } absImport := Import{Hash: rawImport.Hash, Path: absImportPath, Dest: rawImport.Dest, Mode: rawImport.Mode, Uid: rawImport.Uid, Gid: rawImport.Gid} ret.Imports = append(ret.Imports, absImport) } diff --git a/test/import.bats b/test/import.bats index 568e9801..962c24b0 100644 --- a/test/import.bats +++ b/test/import.bats @@ -393,3 +393,21 @@ EOF stacker build } + +@test "import with dir contents" { + mkdir folder1 + touch folder1/file1 + cat > stacker.yaml <