Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't execute gitea.exe on Windows in cmd.exe #22063

Closed
crackedmind opened this issue Dec 7, 2022 · 7 comments · Fixed by #22073
Closed

Can't execute gitea.exe on Windows in cmd.exe #22063

crackedmind opened this issue Dec 7, 2022 · 7 comments · Fixed by #22073
Labels

Comments

@crackedmind
Copy link

crackedmind commented Dec 7, 2022

Description

>gitea-1.18.0-rc1-windows-4.0-amd64.exe --help
2022/12/07 23:15:28 ...s/setting/setting.go:516:1() [F] Failed to get app path: exec: "gitea.exe": cannot run executable found relative to current directory

From powershell it starts normally.

And it' working as expected in cmd.exe for 1.17.3

>gitea-1.17.3-windows-4.0-amd64.exe --help
NAME:
   Gitea - A painless self-hosted Git service

Gitea Version

1.18-rc1

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

Windows 11

How are you running Gitea?

Official gitea-1.18.0-rc1-windows-4.0-amd64.exe

Database

None

@eeyrjmr
Copy link
Contributor

eeyrjmr commented Dec 7, 2022

Duplicate of #21943

NOTE: it might have been premature to close the other issue as it just captures a "workaround" not the change in behaviour (or regression...)

@KazzmanK
Copy link
Contributor

KazzmanK commented Dec 7, 2022

but it still runs as windows service as previously.

@zeripath
Copy link
Contributor

zeripath commented Dec 7, 2022

I wonder if this would fix this?

diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index f0d7f0292..6d99ffa0f 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,13 @@ func getAppPath() (string, error) {
 		appPath, err = exec.LookPath(os.Args[0])
 	}
 
+	if err != nil {
+		if !errors.Is(err, exec.ErrDot) {
+			return "", err
+		}
+		appPath, err = os.Getwd()
+		appPath = filepath.Join(appPath, os.Args[0])
+	}
 	if err != nil {
 		return "", err
 	}

@zeripath
Copy link
Contributor

zeripath commented Dec 7, 2022

The trouble is I can't test this because I don't run windows.

@eeyrjmr
Copy link
Contributor

eeyrjmr commented Dec 7, 2022

The trouble is I can't test this because I don't run windows.

If I can figure out how to cross compile in Gentoo , I can test

@zeripath
Copy link
Contributor

zeripath commented Dec 7, 2022

make release-windows

@zeripath
Copy link
Contributor

zeripath commented Dec 8, 2022

ok so it looks like my patch does work!

Right I'll try to clean it up a bit and push it up as a fix.

zeripath added a commit to zeripath/gitea that referenced this issue Dec 8, 2022
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 go-gitea#22063

Signed-off-by: Andrew Thornton <art27@cantab.net>
techknowlogick added a commit that referenced this issue Dec 14, 2022
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 <art27@cantab.net>

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
zeripath added a commit to zeripath/gitea that referenced this issue Dec 14, 2022
Backport go-gitea#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 go-gitea#22063

Signed-off-by: Andrew Thornton <art27@cantab.net>
jolheiser pushed a commit that referenced this issue Dec 14, 2022
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 <art27@cantab.net>
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants