Skip to content

Commit

Permalink
feat(import): allow dest dir renaming during import
Browse files Browse the repository at this point in the history
import:
    - path: folder1
    dest: /folder2

will cause contents of folder1 to show up as and under /folder2

Signed-off-by: Ramkumar Chinchani <[email protected]>
  • Loading branch information
rchincha committed Oct 10, 2023
1 parent 9042e4d commit 25ee212
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions pkg/stacker/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -163,10 +167,14 @@ 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) {
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())
destpath = path.Join(cacheDir, d.Path())
}

if d.New().IsDir() {
Expand Down
4 changes: 2 additions & 2 deletions test/import.bats
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,10 @@ fifth:
- 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 ]
Expand Down

0 comments on commit 25ee212

Please sign in to comment.