From fa1a3ae87ef8dcd75cc3e8af514f7a68557e34b0 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Thu, 8 Dec 2022 21:47:30 +0000 Subject: [PATCH 1/2] Make gitea work using cmd.exe again Gitea will attempt to lookup its location using LookPath however, this fails on cmd.exe if gitea is in the current working directory. exec.LookPath will return an exec.ErrDot error which we can test for and then simply using filepath.Abs(os.Args[0]) to absolute gitea against the current working directory. Fix #22063 Signed-off-by: Andrew Thornton --- modules/setting/setting.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index f0d7f029271c9..98ac641599cad 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -6,6 +6,7 @@ package setting import ( "encoding/base64" + "errors" "fmt" "math" "net" @@ -465,6 +466,12 @@ func getAppPath() (string, error) { appPath, err = exec.LookPath(os.Args[0]) } + if err != nil { + if !errors.Is(err, exec.ErrDot) { + return "", err + } + appPath, err = filepath.Abs(os.Args[0]) + } if err != nil { return "", err } From 88a527019b14df4269a46389969fa8a517a4c09a Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 13 Dec 2022 08:27:19 +0000 Subject: [PATCH 2/2] fix to work on go1.18 Signed-off-by: Andrew Thornton --- modules/setting/setting.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 98ac641599cad..654cf159cd6ef 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -6,7 +6,6 @@ package setting import ( "encoding/base64" - "errors" "fmt" "math" "net" @@ -467,7 +466,8 @@ func getAppPath() (string, error) { } if err != nil { - if !errors.Is(err, exec.ErrDot) { + // FIXME: Once we switch to go 1.19 use !errors.Is(err, exec.ErrDot) + if !strings.Contains(err.Error(), "cannot run executable found relative to current directory") { return "", err } appPath, err = filepath.Abs(os.Args[0])