-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Use correct path to snap binary #17274
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
Changes from all commits
4af349d
c724989
2726954
1234cfc
d4e249f
aea4f08
e716e64
00fa296
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -431,7 +431,14 @@ func IsProd() bool { | |
} | ||
|
||
func getAppPath() (string, error) { | ||
var appPath string | ||
appPath := AppPath | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if giteaAppPath, ok := os.LookupEnv("GITEA_APP_PATH"); ok { | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
appPath = giteaAppPath | ||
} | ||
if appPath != "" { | ||
return appPath, nil | ||
} | ||
|
||
var err error | ||
if IsWindows && filepath.IsAbs(os.Args[0]) { | ||
appPath = filepath.Clean(os.Args[0]) | ||
|
@@ -446,9 +453,24 @@ func getAppPath() (string, error) { | |
if err != nil { | ||
return "", err | ||
} | ||
|
||
// Note: we don't use path.Dir here because it does not handle case | ||
// which path starts with two "/" in Windows: "//psf/Home/..." | ||
return strings.ReplaceAll(appPath, "\\", "/"), err | ||
appPath = strings.ReplaceAll(appPath, "\\", "/") | ||
|
||
// Fix issue 16209: When running in a snap and repositories are | ||
// created, paths in the hooks include the snap revision. But as new | ||
// revisions come out the older revisions are eventually deleted, and | ||
// the hooks begin to fail. | ||
// The code below replaces the snap revision with "current", which | ||
// is a link to the current snap revision. | ||
snapPath := os.Getenv("SNAP") | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if snapPath != "" && strings.HasPrefix(appPath, snapPath) { | ||
revision := os.Getenv("SNAP_REVISION") | ||
appPath = strings.Replace(appPath, revision, "current", 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should be more careful about the string replacement. Snap document says that the SNAP_REVISION can be something like "x1" (https://snapcraft.io/docs/environment-variables) , a very short string. Maybe there will be other revision strings in future. So maybe we should just split the appPath and check if the second last field is SNAP_REVISION and replace it, and check the gitea binary existence again. And print a log here to tell users we changed the app path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. Then the code would be like what I proposed in PR 17157, but with an added check that the second last field is SNAP_REVISION. That would also include a check with exec.LookPath() that the modified path will actually work. |
||
} | ||
|
||
return appPath, nil | ||
} | ||
|
||
func getWorkPath(appPath string) string { | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SNAP
andSNAP_REVISION
are not intended to be used by real users. So Maybe they can be written in other sections and warn users do not set these variables manually.