mirror of
https://github.com/appleboy/drone-scp.git
synced 2026-06-04 18:23:59 +08:00
feat(tar): add unlink-first flag (#141)
This commit is contained in:
@@ -259,6 +259,11 @@ func main() {
|
||||
Usage: "use --overwrite flag with tar",
|
||||
EnvVars: []string{"PLUGIN_OVERWRITE", "SCP_OVERWRITE", "INPUT_OVERWRITE"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "unlink.first",
|
||||
Usage: "use --unlink-first flag with tar",
|
||||
EnvVars: []string{"PLUGIN_UNLINK_FIRST", "SCP_UNLINK_FIRST", "INPUT_UNLINK_FIRST"},
|
||||
},
|
||||
}
|
||||
|
||||
// Override a template
|
||||
@@ -334,6 +339,7 @@ func run(c *cli.Context) error {
|
||||
TarExec: c.String("tar.exec"),
|
||||
TarTmpPath: c.String("tar.tmp-path"),
|
||||
Overwrite: c.Bool("overwrite"),
|
||||
UnlinkFirst: c.Bool("unlink.first"),
|
||||
Ciphers: c.StringSlice("ciphers"),
|
||||
UseInsecureCipher: c.Bool("useInsecureCipher"),
|
||||
Proxy: easyssh.DefaultConfig{
|
||||
|
||||
@@ -63,6 +63,7 @@ type (
|
||||
Proxy easyssh.DefaultConfig
|
||||
Debug bool
|
||||
Overwrite bool
|
||||
UnlinkFirst bool
|
||||
Ciphers []string
|
||||
UseInsecureCipher bool
|
||||
}
|
||||
@@ -225,6 +226,10 @@ func (p *Plugin) buildArgs(target string) []string {
|
||||
args = append(args, "--overwrite")
|
||||
}
|
||||
|
||||
if p.Config.UnlinkFirst {
|
||||
args = append(args, "--unlink-first")
|
||||
}
|
||||
|
||||
args = append(args,
|
||||
"-C",
|
||||
target,
|
||||
|
||||
+21
-2
@@ -638,8 +638,9 @@ func TestPlugin_buildArgs(t *testing.T) {
|
||||
name: "default command",
|
||||
fields: fields{
|
||||
Config: Config{
|
||||
Overwrite: false,
|
||||
TarExec: "tar",
|
||||
Overwrite: false,
|
||||
UnlinkFirst: false,
|
||||
TarExec: "tar",
|
||||
},
|
||||
DestFile: "foo.tar",
|
||||
},
|
||||
@@ -653,6 +654,7 @@ func TestPlugin_buildArgs(t *testing.T) {
|
||||
fields: fields{
|
||||
Config: Config{
|
||||
Overwrite: false,
|
||||
UnlinkFirst: false,
|
||||
TarExec: "tar",
|
||||
StripComponents: 2,
|
||||
},
|
||||
@@ -670,6 +672,7 @@ func TestPlugin_buildArgs(t *testing.T) {
|
||||
TarExec: "tar",
|
||||
StripComponents: 2,
|
||||
Overwrite: true,
|
||||
UnlinkFirst: false,
|
||||
},
|
||||
DestFile: "foo.tar",
|
||||
},
|
||||
@@ -678,6 +681,22 @@ func TestPlugin_buildArgs(t *testing.T) {
|
||||
},
|
||||
want: []string{"tar", "-xf", "foo.tar", "--strip-components", "2", "--overwrite", "-C", "foo"},
|
||||
},
|
||||
{
|
||||
name: "unlink first",
|
||||
fields: fields{
|
||||
Config: Config{
|
||||
TarExec: "tar",
|
||||
StripComponents: 2,
|
||||
Overwrite: true,
|
||||
UnlinkFirst: true,
|
||||
},
|
||||
DestFile: "foo.tar",
|
||||
},
|
||||
args: args{
|
||||
target: "foo",
|
||||
},
|
||||
want: []string{"tar", "-xf", "foo.tar", "--strip-components", "2", "--overwrite", "--unlink-first", "-C", "foo"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user