diff --git a/pkg/stacker/import.go b/pkg/stacker/import.go index dbcbcd7f..377b64ff 100644 --- a/pkg/stacker/import.go +++ b/pkg/stacker/import.go @@ -126,7 +126,11 @@ func importFile(imp string, cacheDir string, hash string, idest string, mode *fs var dest string if imp[len(imp)-1:] != "/" { - dest = path.Join(cacheDir, path.Base(imp)) + if idest != "" && path.Base(imp) != path.Base(idest) { + dest = path.Join(cacheDir, path.Base(idest)) + } else { + dest = path.Join(cacheDir, path.Base(imp)) + } } else { dest = cacheDir } @@ -163,10 +167,18 @@ func importFile(imp string, cacheDir string, hash string, idest string, mode *fs case mtree.Extra: srcpath := path.Join(imp, d.Path()) var destpath string - if imp[len(imp)-1:] == "/" { - destpath = path.Join(cacheDir, d.Path()) + if imp[len(imp)-1:] != "/" { + if idest != "" && path.Base(imp) != path.Base(idest) { + if idest[len(idest)-1:] != "/" { + destpath = path.Join(cacheDir, path.Base(idest), d.Path()) + } else { + destpath = path.Join(cacheDir, path.Base(imp), d.Path()) + } + } else { + destpath = path.Join(cacheDir, path.Base(imp), d.Path()) + } } else { - destpath = path.Join(cacheDir, path.Base(imp), d.Path()) + destpath = path.Join(cacheDir, d.Path()) } if d.New().IsDir() { @@ -360,7 +372,7 @@ func Import(c types.StackerConfig, storage types.Storage, name string, imports t dest := i.Dest - if i.Dest[len(i.Dest)-1:] != "/" { + if i.Dest[len(i.Dest)-1:] != "/" && i.Path[len(i.Path)-1:] != "/" { dest = path.Dir(i.Dest) } diff --git a/test/import.bats b/test/import.bats index 7adfd201..436f4f1a 100644 --- a/test/import.bats +++ b/test/import.bats @@ -450,19 +450,70 @@ fifth: - path: folder1/subfolder2/ dest: /folder3/ - path: folder1/subfolder2 - dest: /folder4/ + dest: /folder4 - path: stacker://fourth/folder4/subfolder5/ dest: /folder6/ - path: stacker://fourth/folder4/ dest: /folder7/ run: | - ls -l / + ls -l /folder* [ -f /folder3/subfile1 ] [ ! -e /folder3/subfolder2 ] - [ -f /folder4/subfolder2/subfile1 ] + [ -f /folder4/subfile1 ] [ -f /folder6/subfile6 ] [ ! -e /folder6/subfolder5 ] [ -f /folder7/subfolder5/subfile6 ] EOF stacker build } + +@test "dir path behavior" { + mkdir -p folder1 + touch folder1/file1 + mkdir -p folder1/subfolder2 + touch folder1/subfolder2/subfile1 + cat > stacker.yaml <