From 9fd92d10dc46466c075f219567d431d1250462f8 Mon Sep 17 00:00:00 2001 From: Maciej Nowak Date: Fri, 14 Jul 2023 13:35:46 +0000 Subject: [PATCH] fix: Do not create base folder on remote when uploading dir Calling lxc files push dir/ instance:/tmp/abc will create folder /tmp/abc/dir with all files inside which does not match behavior expected by Packer - files should be placed directly under /tmp/abc. Use lxc files push dir/* to upload files to proper directory --- builder/lxd/communicator.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/builder/lxd/communicator.go b/builder/lxd/communicator.go index fe4aa7f..25abc77 100644 --- a/builder/lxd/communicator.go +++ b/builder/lxd/communicator.go @@ -11,6 +11,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "syscall" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" @@ -92,7 +93,10 @@ func (c *Communicator) Upload(dst string, r io.Reader, fi *os.FileInfo) error { func (c *Communicator) UploadDir(dst string, src string, exclude []string) error { fileDestination := fmt.Sprintf("%s/%s", c.ContainerName, dst) - pushCommand := fmt.Sprintf("lxc file push --debug -pr %s %s", src, fileDestination) + if !strings.HasSuffix(src, "/") { + src += "/" + } + pushCommand := fmt.Sprintf("lxc file push --debug -pr %s* %s", src, fileDestination) log.Printf(pushCommand) cp, err := c.CmdWrapper(pushCommand) if err != nil {