Scatter/gather for client->server copy now functional

This commit is contained in:
Russ Magee 2018-08-30 20:06:42 -07:00
parent 6389ad49d5
commit 143990da34
2 changed files with 17 additions and 15 deletions

View File

@ -16,6 +16,7 @@ import (
"os"
"os/exec"
"os/user"
"path"
"runtime"
"strings"
"sync"
@ -106,10 +107,20 @@ 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
// its use below, where clients can send scattered sets of source
// files and dirs to be extraced to a single dest dir server-side,
// whilst preserving the subtrees of dirs on the other side. :)
// Eg., tar -c -f /dev/stdout -C /dirA fileInA -C /some/where/dirB fileInB /foo/dirC
// packages fileInA, fileInB, and dirC at a single toplevel in the tar.
// The tar authors are/were real smarties :)
for _, v := range strings.Split(files, " ") {
cmdArgs = append(cmdArgs, v)
dirTmp, fileTmp := path.Split(v)
cmdArgs = append(cmdArgs, "-C", dirTmp, fileTmp)
//cmdArgs = append(cmdArgs, v)
}
fmt.Printf("[%v %v]\n", cmdName, cmdArgs)
@ -160,7 +171,7 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, rec *cmdSpec)
cmdName := "/bin/tar"
destPath := files
cmdArgs := []string{"-x", "-C", destPath}
cmdArgs := []string{"-xz", "-C", destPath}
fmt.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

View File

@ -66,22 +66,13 @@ func runClientToServerCopyAs(who string, conn hkexnet.Conn, fpath string, chaffi
} else {
destDir = path.Join(u.HomeDir, fpath)
}
//stat, pe := os.Stat(destDir)
//_ = stat
//if pe != nil {
// log.Fatal(pe)
// return pe, 252 // ?!
//}
//if stat.IsDir(destBase) {
cmdArgs := []string{"-x", "-C", destDir}
//} else {
// cmdArgs := []string{"-x",
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
// (as this isn't input from a shell) (right? -rlm 20180823)
//cmdArgs := []string{"-xvz", "-C", destPath, `--xform=s#.*/\(.*\)#\1#`}
//cmdArgs := []string{"-x", "-C", destDir, `--xform=s#.*/\(.*\)#\1#`}
c = exec.Command(cmdName, cmdArgs...)
c.Dir = destDir
@ -152,7 +143,7 @@ func runServerToClientCopyAs(who string, conn hkexnet.Conn, srcPath string, chaf
cmdName := "/bin/tar"
//cmdArgs := []string{"-c", "-f", "-", srcPath}
srcDir, srcBase := path.Split(srcPath)
cmdArgs := []string{"-c", "-C", srcDir, "-f", "-", srcBase}
cmdArgs := []string{"-cz", "-C", srcDir, "-f", "-", srcBase}
c = exec.Command(cmdName, cmdArgs...)