feat(tar): add Overwrite flag (#102)

* feat(tar): add Overwrite flag

* chore: remove

* chore: output

* chore: output
This commit is contained in:
Bo-Yi Wu
2019-09-28 16:59:01 +08:00
committed by GitHub
parent 933b45bc15
commit c85ca1ffd2
3 changed files with 99 additions and 4 deletions
+16 -4
View File
@@ -61,6 +61,7 @@ type (
TarTmpPath string
Proxy easyssh.DefaultConfig
Debug bool
Overwrite bool
}
// Plugin values.
@@ -196,8 +197,7 @@ type fileList struct {
Source []string
}
// Args get tar command
func (p *Plugin) Args(target string) []string {
func (p *Plugin) buildArgs(target string) []string {
args := []string{}
args = append(args,
@@ -211,6 +211,10 @@ func (p *Plugin) Args(target string) []string {
args = append(args, strconv.Itoa(p.Config.StripComponents))
}
if p.Config.Overwrite {
args = append(args, "--overwrite")
}
args = append(args,
"-C",
target,
@@ -326,11 +330,19 @@ func (p *Plugin) Exec() error {
// untar file
p.log(host, "untar file", p.DestFile)
commamd := strings.Join(p.Args(target), " ")
commamd := strings.Join(p.buildArgs(target), " ")
if p.Config.Debug {
fmt.Println("$", commamd)
}
_, _, _, err = ssh.Run(commamd, p.Config.CommandTimeout)
outStr, errStr, _, err := ssh.Run(commamd, p.Config.CommandTimeout)
if outStr != "" {
p.log(host, "output: ", outStr)
}
if errStr != "" {
p.log(host, "error: ", errStr)
}
if err != nil {
errChannel <- err