diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index cceeeb5eb..b32ad3ea7 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -169,7 +169,7 @@ func (c *comm) DownloadDir(src string, dst string, excl []string) error { break case 'E': dirStack = dirStack[:len(dirStack)-1] - if len(dirStack) == 1 { + if len(dirStack) == 0 { fmt.Fprint(w, "\x00") return nil } @@ -178,11 +178,11 @@ func (c *comm) DownloadDir(src string, dst string, excl []string) error { return fmt.Errorf("unexpected server response (%x)", fi[0]) } - var mode string + var mode int64 var size int64 var name string log.Printf("Download dir str:%s", fi) - n, err := fmt.Sscanf(fi, "%6s %d %s", &mode, &size, &name) + n, err := fmt.Sscanf(fi[1:], "%o %d %s", &mode, &size, &name) if err != nil || n != 3 { return fmt.Errorf("can't parse server response (%s)", fi) } @@ -190,12 +190,12 @@ func (c *comm) DownloadDir(src string, dst string, excl []string) error { return fmt.Errorf("negative file size") } - log.Printf("Download dir mode:%s size:%d name:%s", mode, size, name) + log.Printf("Download dir mode:%0o size:%d name:%s", mode, size, name) dst = filepath.Join(dirStack...) switch fi[0] { case 'D': - err = os.MkdirAll(filepath.Join(dst, name), os.FileMode(0755)) + err = os.MkdirAll(filepath.Join(dst, name), os.FileMode(mode)) if err != nil { return err } @@ -203,7 +203,7 @@ func (c *comm) DownloadDir(src string, dst string, excl []string) error { continue case 'C': fmt.Fprint(w, "\x00") - err = scpDownloadFile(filepath.Join(dst, name), stdoutR, size, os.FileMode(0644)) + err = scpDownloadFile(filepath.Join(dst, name), stdoutR, size, os.FileMode(mode)) if err != nil { return err } diff --git a/post-processor/checksum/post-processor.go b/post-processor/checksum/post-processor.go index 8bfa589d4..82d8c39a0 100644 --- a/post-processor/checksum/post-processor.go +++ b/post-processor/checksum/post-processor.go @@ -93,13 +93,8 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac h = getHash(ct) for _, art := range files { - if len(artifact.Files()) > 1 { - checksumFile = filepath.Join(filepath.Dir(art), ct+"sums") - } else if p.config.OutputPath != "" { - checksumFile = p.config.OutputPath - } else { - checksumFile = fmt.Sprintf("%s.%s", art, ct+"sum") - } + checksumFile = p.config.OutputPath + if _, err := os.Stat(checksumFile); err != nil { newartifact.files = append(newartifact.files, checksumFile) } @@ -124,6 +119,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac fr.Close() fw.WriteString(fmt.Sprintf("%x\t%s\n", h.Sum(nil), filepath.Base(art))) fw.Close() + h.Reset() } } diff --git a/provisioner/file/provisioner.go b/provisioner/file/provisioner.go index 49498d08d..19e5c4bea 100644 --- a/provisioner/file/provisioner.go +++ b/provisioner/file/provisioner.go @@ -95,12 +95,15 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { func (p *Provisioner) ProvisionDownload(ui packer.Ui, comm packer.Communicator) error { for _, src := range p.config.Sources { - ui.Say(fmt.Sprintf("Downloading %s => %s", src, p.config.Destination)) + dst := p.config.Destination + ui.Say(fmt.Sprintf("Downloading %s => %s", src, dst)) // ensure destination dir exists. p.config.Destination may either be a file or a dir. - dir := p.config.Destination + dir := dst // if it doesn't end with a /, set dir as the parent dir - if !strings.HasSuffix(p.config.Destination, "/") { + if !strings.HasSuffix(dst, "/") { dir = filepath.Dir(dir) + } else if !strings.HasSuffix(src, "/") && !strings.HasSuffix(src, "*") { + dst = filepath.Join(dst, filepath.Base(src)) } if dir != "" { err := os.MkdirAll(dir, os.FileMode(0755)) @@ -108,12 +111,12 @@ func (p *Provisioner) ProvisionDownload(ui packer.Ui, comm packer.Communicator) return err } } - // if the config.Destination was a dir, download the dir - if strings.HasSuffix(p.config.Destination, "/") { - return comm.DownloadDir(src, p.config.Destination, nil) + // if the src was a dir, download the dir + if strings.HasSuffix(src, "/") || strings.IndexAny(src, "*?[") >= 0 { + return comm.DownloadDir(src, dst, nil) } - f, err := os.OpenFile(p.config.Destination, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) + f, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) if err != nil { return err } @@ -130,7 +133,9 @@ func (p *Provisioner) ProvisionDownload(ui packer.Ui, comm packer.Communicator) func (p *Provisioner) ProvisionUpload(ui packer.Ui, comm packer.Communicator) error { for _, src := range p.config.Sources { - ui.Say(fmt.Sprintf("Uploading %s => %s", src, p.config.Destination)) + dst := p.config.Destination + + ui.Say(fmt.Sprintf("Uploading %s => %s", src, dst)) info, err := os.Stat(src) if err != nil { @@ -154,7 +159,11 @@ func (p *Provisioner) ProvisionUpload(ui packer.Ui, comm packer.Communicator) er return err } - err = comm.Upload(p.config.Destination, f, &fi) + if strings.HasSuffix(dst, "/") { + dst = filepath.Join(dst, filepath.Base(src)) + } + + err = comm.Upload(dst, f, &fi) if err != nil { ui.Error(fmt.Sprintf("Upload failed: %s", err)) return err