aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Cholewiński <harry666t@gmail.com>2018-01-04 21:14:26 +0100
committerKamil Cholewiński <harry666t@gmail.com>2018-01-04 21:18:47 +0100
commitc47dee1b2c47f46eb0146ede14de5ac8cc2fc7b8 (patch)
tree466b8708b28f221c96b47896adb358a5e8ac0057
parent5cde7abf5e6e99bf2d89602f0c8e5458fd2926d5 (diff)
downloadjudo-c47dee1b2c47f46eb0146ede14de5ac8cc2fc7b8.zip
judo-c47dee1b2c47f46eb0146ede14de5ac8cc2fc7b8.tar.gz
judo-c47dee1b2c47f46eb0146ede14de5ac8cc2fc7b8.tar.bz2
Fix shquote, add shargs
-rw-r--r--transport.go25
1 files changed, 23 insertions, 2 deletions
diff --git a/transport.go b/transport.go
index b979381..afdc621 100644
--- a/transport.go
+++ b/transport.go
@@ -1,8 +1,10 @@
package main
import (
+ "bytes"
"fmt"
"os"
+ "strings"
"time"
)
@@ -40,8 +42,27 @@ func (host *Host) pushFiles(job *Job,
}
func shquote(s string) string {
- // TODO: quote literal inline '
- return fmt.Sprintf(`'%s'`, s)
+ var b bytes.Buffer
+ b.WriteRune('\'')
+ for _, c := range s {
+ if c == '\'' { // ASCII "'"
+ b.WriteString("'\\''")
+ } else {
+ b.WriteRune(c)
+ }
+ }
+ b.WriteRune('\'')
+ return b.String()
+}
+
+// Serialize an array of strings into a string that, when passed to a
+// shell, will again be interpreted as the same array of strings.
+func shargs(ss []string) string {
+ var qs []string
+ for _, s := range ss {
+ qs = append(qs, shquote(s))
+ }
+ return strings.Join(ss, " ")
}
func (host *Host) startSSH(job *Job, command string) (proc *Proc, err error) {