diff --git a/service/service.go b/service/service.go index a20004d..f49ce92 100644 --- a/service/service.go +++ b/service/service.go @@ -6,11 +6,8 @@ import ( "fmt" "io" "os" - "os/exec" "path/filepath" - "runtime" "strings" - "syscall" "github.com/sinbad/lfs-folderstore/api" "github.com/sinbad/lfs-folderstore/util" @@ -253,7 +250,7 @@ func store(baseDir string, oid string, size int64, a *api.Action, fromPath strin } func gitDir() (string, error) { - cmd := newCmd("git", "rev-parse", "--git-dir") + cmd := util.NewCmd("git", "rev-parse", "--git-dir") out, err := cmd.Output() if err != nil { return "", fmt.Errorf("Failed to call git rev-parse --git-dir: %v %v", err, string(out)) @@ -263,14 +260,6 @@ func gitDir() (string, error) { } -func newCmd(name string, arg ...string) *exec.Cmd { - cmd := exec.Command(name, arg...) - if runtime.GOOS == "windows" { - cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} - } - return cmd -} - func absPath(path string) (string, error) { if len(path) > 0 { path, err := filepath.Abs(path) diff --git a/util/cmd_notwindows.go b/util/cmd_notwindows.go new file mode 100644 index 0000000..f80b9a6 --- /dev/null +++ b/util/cmd_notwindows.go @@ -0,0 +1,10 @@ +// +build !windows + +package util + +import "os/exec" + +func NewCmd(name string, arg ...string) *exec.Cmd { + cmd := exec.Command(name, arg...) + return cmd +} diff --git a/util/cmd_windows.go b/util/cmd_windows.go new file mode 100644 index 0000000..272a73a --- /dev/null +++ b/util/cmd_windows.go @@ -0,0 +1,12 @@ +package util + +import ( + "os/exec" + "syscall" +) + +func NewCmd(name string, arg ...string) *exec.Cmd { + cmd := exec.Command(name, arg...) + cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} + return cmd +}