From 29bbe10c1ce2ec6e92b703634c020965b9e9d888 Mon Sep 17 00:00:00 2001 From: Chris Lundquist Date: Fri, 27 Jan 2017 21:06:18 +0000 Subject: [PATCH] [lxd] rework local tar command to avoid chdir --- builder/lxd/communicator.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builder/lxd/communicator.go b/builder/lxd/communicator.go index 3df1cf8bc..abb1f16a1 100644 --- a/builder/lxd/communicator.go +++ b/builder/lxd/communicator.go @@ -70,13 +70,15 @@ func (c *Communicator) UploadDir(dst string, src string, exclude []string) error // NOTE:lxc file push doesn't yet support directory uploads. // As a work around, we tar up the folder, upload it as a file, then extract it - os.Chdir(src) - tar, err := c.CmdWrapper("tar -czf - .") + // Don't use 'z' flag as compressing may take longer and the transfer is likely local. + // If this isn't the case, it is possible for the user to crompress in another step then transfer. + // It wouldn't be possibe to disable compression, without exposing this option. + tar, err := c.CmdWrapper(fmt.Sprintf("tar -cf - -C %s .", src)) if err != nil { return err } - cp, err := c.CmdWrapper(fmt.Sprintf("lxc exec %s -- tar -xzf - -C %s ", c.ContainerName, dst)) + cp, err := c.CmdWrapper(fmt.Sprintf("lxc exec %s -- tar -xf - -C %s", c.ContainerName, dst)) if err != nil { return err }