diff --git a/path.go b/path.go new file mode 100644 index 0000000..f90fb13 --- /dev/null +++ b/path.go @@ -0,0 +1,7 @@ +// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris + +package main + +func getRealPath(path string) string { + return path +} diff --git a/path_windows.go b/path_windows.go new file mode 100644 index 0000000..90d9c47 --- /dev/null +++ b/path_windows.go @@ -0,0 +1,11 @@ +// +build windows + +package main + +import ( + "strings" +) + +func getRealPath(path string) string { + return "/" + strings.Replace(strings.Replace(path, ":", "", -1), "\\", "/", -1) +} diff --git a/path_windows_test.go b/path_windows_test.go new file mode 100644 index 0000000..4b017a4 --- /dev/null +++ b/path_windows_test.go @@ -0,0 +1,25 @@ +package main + +import "testing" + +func TestGetRealPath(t *testing.T) { + type args struct { + path string + } + tests := []struct { + name string + args args + want string + }{ + { + "Test Windows Path", + "C:\\Users\\appleboy\\test.txt", + "/C/Users/appleboy/test.txt" + } + } + for _, tt := range tests { + if got := getRealPath(tt.args.path); got != tt.want { + t.Errorf("%q. getRealPath() = %v, want %v", tt.name, got, tt.want) + } + } +} diff --git a/plugin.go b/plugin.go index 0bc58a3..e186d2f 100644 --- a/plugin.go +++ b/plugin.go @@ -8,7 +8,6 @@ import ( "os" "os/exec" "path/filepath" - "runtime" "strings" "sync" @@ -100,13 +99,7 @@ func (p Plugin) Exec() error { // run archive command log.Println("tar all files into " + tar) - var args []string - if runtime.GOOS == "windows" { - newTar := "/" + strings.Replace(strings.Replace(tar, ":", "", -1), "\\", "/", -1) - args = append(append([]string{}, "-cf", newTar), files...) - } else { - args = append(append([]string{}, "-cf", tar), files...) - } + args := append(append([]string{}, "-cf", getRealPath(tar)), files...) cmd := exec.Command("tar", args...) cmd.Stdout = os.Stdout