From bff56a2c61e2e89abd4f0d6969f84fcdf87a3f38 Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Thu, 6 Sep 2018 16:37:17 -0700 Subject: [PATCH] -Added -z option back to tarpipes -Moved remaining chatty fmt.Prints to log.Print --- hkexsh/hkexsh.go | 14 +++++++------- hkexshd/hkexshd.go | 10 ++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/hkexsh/hkexsh.go b/hkexsh/hkexsh.go index 4e42f86..6513402 100755 --- a/hkexsh/hkexsh.go +++ b/hkexsh/hkexsh.go @@ -102,7 +102,7 @@ func parseNonSwitchArgs(a []string) (user, host, path string, isDest bool, other // doCopyMode begins a secure hkexsh local<->remote file copy operation. func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, rec *cmdSpec) (err error, exitStatus uint32) { if remoteDest { - fmt.Println("local files:", files, "remote filepath:", string(rec.cmd)) + log.Println("local files:", files, "remote filepath:", string(rec.cmd)) var c *exec.Cmd @@ -111,7 +111,7 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, rec *cmdSpec) //os.Setenv("TERM", "vt102") // TODO: server or client option? cmdName := "/bin/tar" - cmdArgs := []string{"-c", "-f", "/dev/stdout"} + cmdArgs := []string{"-cz", "-f", "/dev/stdout"} files = strings.TrimSpace(files) // Awesome fact: tar actually can take multiple -C args, and // changes to the dest dir *as it sees each one*. This enables @@ -136,14 +136,14 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, rec *cmdSpec) //cmdArgs = append(cmdArgs, v) } - fmt.Printf("[%v %v]\n", cmdName, cmdArgs) + log.Printf("[%v %v]\n", cmdName, cmdArgs) // NOTE the lack of quotes around --xform option's sed expression. // When args are passed in exec() format, no quoting is required // (as this isn't input from a shell) (right? -rlm 20180823) //cmdArgs := []string{"-xvz", "-C", files, `--xform=s#.*/\(.*\)#\1#`} c = exec.Command(cmdName, cmdArgs...) c.Dir, _ = os.Getwd() - fmt.Println("[wd:", c.Dir, "]") + log.Println("[wd:", c.Dir, "]") c.Stdout = conn stdErrBuffer := new(bytes.Buffer) c.Stderr = stdErrBuffer @@ -177,7 +177,7 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, rec *cmdSpec) _, _ = conn.Read(nil /*ackByte*/) } } else { - fmt.Println("remote filepath:", string(rec.cmd), "local files:", files) + log.Println("remote filepath:", string(rec.cmd), "local files:", files) var c *exec.Cmd //os.Clearenv() @@ -187,8 +187,8 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, rec *cmdSpec) cmdName := "/bin/tar" destPath := files - cmdArgs := []string{"-x", "-C", destPath} - fmt.Printf("[%v %v]\n", cmdName, cmdArgs) + cmdArgs := []string{"-xz", "-C", destPath} + log.Printf("[%v %v]\n", cmdName, cmdArgs) // NOTE the lack of quotes around --xform option's sed expression. // When args are passed in exec() format, no quoting is required // (as this isn't input from a shell) (right? -rlm 20180823) diff --git a/hkexshd/hkexshd.go b/hkexshd/hkexshd.go index aa26764..da419d0 100755 --- a/hkexshd/hkexshd.go +++ b/hkexshd/hkexshd.go @@ -68,7 +68,7 @@ func runClientToServerCopyAs(who string, conn hkexnet.Conn, fpath string, chaffi destDir = path.Join(u.HomeDir, fpath) } - cmdArgs := []string{"-x", "-C", destDir} + cmdArgs := []string{"-xz", "-C", destDir} // NOTE the lack of quotes around --xform option's sed expression. // When args are passed in exec() format, no quoting is required @@ -147,7 +147,7 @@ func runServerToClientCopyAs(who string, conn hkexnet.Conn, srcPath string, chaf } srcDir, srcBase := path.Split(srcPath) - cmdArgs := []string{"-c", "-C", srcDir, "-f", "-", srcBase} + cmdArgs := []string{"-cz", "-C", srcDir, "-f", "-", srcBase} c = exec.Command(cmdName, cmdArgs...) @@ -192,12 +192,10 @@ func runServerToClientCopyAs(who string, conn hkexnet.Conn, srcPath string, chaf // an ExitStatus() method with the same signature. if status, ok := exiterr.Sys().(syscall.WaitStatus); ok { exitStatus = uint32(status.ExitStatus()) - log.Printf("Exit Status: %d", exitStatus) - // TODO: send stdErrBuffer to client via specific packet - // type so it can inform user if len(stdErrBuffer.Bytes()) > 0 { - fmt.Print("TODO: (stderrBuffer to client):", stdErrBuffer) + log.Print(stdErrBuffer) } + log.Printf("Exit Status: %d", exitStatus) } } }