communicator/ssh: dir upload works when dir contains symlinks [Gh-449]

This commit is contained in:
Mitchell Hashimoto 2013-09-25 10:42:49 +02:00
parent 3e82c6cf12
commit 8cdb92e327
2 changed files with 23 additions and 2 deletions

View File

@ -4,6 +4,8 @@ BUG FIXES:
* core: default user variable values don't need to be strings. [GH-456] * core: default user variable values don't need to be strings. [GH-456]
* builder/amazon-chroot: Fix errors with waitin for state change. [GH-459] * builder/amazon-chroot: Fix errors with waitin for state change. [GH-459]
* communicator/ssh: SCP uploads now work properly when directories
contain symlinks. [GH-449]
## 0.3.8 (September 22, 2013) ## 0.3.8 (September 22, 2013)

View File

@ -408,8 +408,27 @@ func scpUploadDir(root string, fs []os.FileInfo, w io.Writer, r *bufio.Reader) e
for _, fi := range fs { for _, fi := range fs {
realPath := filepath.Join(root, fi.Name()) realPath := filepath.Join(root, fi.Name())
if !fi.IsDir() { // Track if this is actually a symlink to a directory. If it is
// It is a regular file, just upload it // a symlink to a file we don't do any special behavior because uploading
// a file just works. If it is a directory, we need to know so we
// treat it as such.
isSymlinkToDir := false
if fi.Mode() & os.ModeSymlink == os.ModeSymlink {
symPath, err := filepath.EvalSymlinks(realPath)
if err != nil {
return err
}
symFi, err := os.Lstat(symPath)
if err != nil {
return err
}
isSymlinkToDir = symFi.IsDir()
}
if !fi.IsDir() && !isSymlinkToDir {
// It is a regular file (or symlink to a file), just upload it
f, err := os.Open(realPath) f, err := os.Open(realPath)
if err != nil { if err != nil {
return err return err