From 2ae15257494d925d67c40ac2af00da127079ae42 Mon Sep 17 00:00:00 2001 From: Vlad Petrov Date: Tue, 16 Oct 2018 22:24:41 +0300 Subject: [PATCH 1/3] Update current path extraction It is recommended to use func Executable since 1.8 https://tip.golang.org/pkg/os/#Executable --- go/cmd/gitlab-shell/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/go/cmd/gitlab-shell/main.go b/go/cmd/gitlab-shell/main.go index ae541518..b42aba78 100644 --- a/go/cmd/gitlab-shell/main.go +++ b/go/cmd/gitlab-shell/main.go @@ -15,7 +15,11 @@ var ( ) func init() { - binDir = filepath.Dir(os.Args[0]) + ex, err := os.Executable() + if err != nil { + panic(err) + } + binDir = filepath.Dir(ex) rootDir = filepath.Dir(binDir) } -- GitLab From c423b34efdfac87641b41983ccb182857dec2b9a Mon Sep 17 00:00:00 2001 From: Vlad Petrov Date: Fri, 5 Apr 2019 00:28:50 +0300 Subject: [PATCH 2/3] fix panic at path extraction --- go/cmd/gitlab-shell/main.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/go/cmd/gitlab-shell/main.go b/go/cmd/gitlab-shell/main.go index b42aba78..f30a1c5d 100644 --- a/go/cmd/gitlab-shell/main.go +++ b/go/cmd/gitlab-shell/main.go @@ -12,15 +12,15 @@ import ( var ( binDir string rootDir string + initErr error ) func init() { - ex, err := os.Executable() - if err != nil { - panic(err) + ex, initErr := os.Executable() + if initErr == nil { + binDir = filepath.Dir(ex) + rootDir = filepath.Dir(binDir) } - binDir = filepath.Dir(ex) - rootDir = filepath.Dir(binDir) } func migrate(*config.Config) (int, bool) { @@ -42,6 +42,10 @@ func execRuby() { } func main() { + if initErr != nil { + fmt.Fprintln(os.Stderr, "Failed to determine configuration file or ruby executable paths, exiting") + os.Exit(1) + } // Fall back to Ruby in case of problems reading the config, but issue a // warning as this isn't something we can sustain indefinitely config, err := config.NewFromDir(rootDir) -- GitLab From 066d3788c2580224bc3b2ba505d171aeb7137634 Mon Sep 17 00:00:00 2001 From: Vlad Petrov Date: Fri, 5 Apr 2019 00:41:27 +0300 Subject: [PATCH 3/3] gofmt for c423b34efdfac87641b41983ccb182857dec2b9a --- go/cmd/gitlab-shell/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/cmd/gitlab-shell/main.go b/go/cmd/gitlab-shell/main.go index f30a1c5d..640eba1f 100644 --- a/go/cmd/gitlab-shell/main.go +++ b/go/cmd/gitlab-shell/main.go @@ -12,7 +12,7 @@ import ( var ( binDir string rootDir string - initErr error + initErr error ) func init() { -- GitLab