Skip to content

Commit

Permalink
Create dir to fix nested file send
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Jun 23, 2018
1 parent 24d9686 commit e2d7870
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
11 changes: 6 additions & 5 deletions client/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"io/ioutil"
"os"
"path"
"path/filepath"

"github.com/ubclaunchpad/inertia/cfg"
"golang.org/x/crypto/ssh"
Expand Down Expand Up @@ -124,22 +124,23 @@ func (runner *SSHRunner) CopyFile(file io.Reader, remotePath string, permissions
}
reader := bytes.NewReader(contents)

// Send file contents
filename := path.Base(remotePath)
directory := path.Dir(remotePath)
// Set up
filename := filepath.Base(remotePath)
directory := filepath.Dir(remotePath)
session, err := getSSHSession(runner.pem, runner.ip, runner.sshPort, runner.user)
if err != nil {
return err
}

// Send file contents
go func() {
w, _ := session.StdinPipe()
defer w.Close()
fmt.Fprintln(w, "C"+permissions, len(contents), filename)
io.Copy(w, reader)
fmt.Fprintln(w, "\x00")
}()
session.Run("/usr/bin/scp -t " + directory)
session.Run("mkdir -p " + directory + "; /usr/bin/scp -t " + directory)
return nil
}

Expand Down
9 changes: 1 addition & 8 deletions deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"
"os"
"path"
"path/filepath"
"strings"

"github.com/ubclaunchpad/inertia/common"
Expand Down Expand Up @@ -379,13 +378,7 @@ deployment. Provide a relative path to your file.`,
if err != nil {
log.Fatal(err.Error())
}
if dest != "" {
// If path is defined, dest = [path]/[filename], with the user-provided
// path to the source file stripped out
dest = path.Join(dest, filepath.Base(args[0]))
} else {
// Otherwise, dest = [filepath], where [filepath] is what the user
// provided to the command
if dest == "" {
dest = args[0]
}

Expand Down

0 comments on commit e2d7870

Please sign in to comment.