From 493210aaf01b159f6a3c2088d4b1ce5c9f17156b Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Mon, 1 May 2023 20:27:19 +0000 Subject: [PATCH] fix: support dest path for import-http Fixes issue #456 Signed-off-by: Ramkumar Chinchani --- pkg/stacker/import.go | 2 +- pkg/stacker/network.go | 9 +++++++-- test/import-http.bats | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/pkg/stacker/import.go b/pkg/stacker/import.go index 67d8cd74..5bb5902c 100644 --- a/pkg/stacker/import.go +++ b/pkg/stacker/import.go @@ -248,7 +248,7 @@ func acquireUrl(c types.StackerConfig, storage types.Storage, i string, cache st return "", errors.Errorf("The requested hash of %s import is different than the actual hash: %s != %s", i, expectedHash, remoteHash) } - return Download(cache, i, progress, expectedHash, remoteHash, remoteSize, mode, uid, gid) + return Download(cache, i, progress, expectedHash, remoteHash, remoteSize, idest, mode, uid, gid) } else if url.Scheme == "stacker" { // we always Grab() things from stacker://, because we need to // mount the container's rootfs to get them and don't diff --git a/pkg/stacker/network.go b/pkg/stacker/network.go index 878a2b56..3924d378 100644 --- a/pkg/stacker/network.go +++ b/pkg/stacker/network.go @@ -18,9 +18,14 @@ import ( // download with caching support in the specified cache dir. func Download(cacheDir string, url string, progress bool, expectedHash, remoteHash, remoteSize string, - mode *fs.FileMode, uid, gid int, + idest string, mode *fs.FileMode, uid, gid int, ) (string, error) { - name := path.Join(cacheDir, path.Base(url)) + var name string + if idest != "" && idest[len(idest)-1:] != "/" { + name = path.Join(cacheDir, path.Base(idest)) + } else { + name = path.Join(cacheDir, path.Base(url)) + } if fi, err := os.Stat(name); err == nil { // Couldn't get remoteHash then use cached copy of import diff --git a/test/import-http.bats b/test/import-http.bats index 81235983..9ef6b8ee 100644 --- a/test/import-http.bats +++ b/test/import-http.bats @@ -73,4 +73,34 @@ function teardown() { [ "$(sha reference/nm_orig)" == "$(sha dest/img/rootfs/root/nm)" ] } +@test "importing to a dest" { + cat > img/stacker1.yaml < img/stacker2.yaml <