From 1805075b5e02754b8f8eecfaf7d8a01df04bd109 Mon Sep 17 00:00:00 2001 From: zeripath Date: Wed, 14 Dec 2022 06:15:11 +0000 Subject: [PATCH] Make gitea work using cmd.exe again (#22073) Backport #22073 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 bb2281f13b244..5fe4682968b34 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -464,6 +464,13 @@ func getAppPath() (string, error) { appPath, err = exec.LookPath(os.Args[0]) } + if err != nil { + // 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]) + } if err != nil { return "", err }