Skip to content

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

Closed
wants to merge 8 commits into from

Conversation

techknowlogick
Copy link
Member

@techknowlogick techknowlogick commented Oct 8, 2021

replace #17157
Fixes #16209

co-authored-by: @OleHusgaard

@techknowlogick techknowlogick added type/bug skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. hacktoberfest-accepted labels Oct 8, 2021
@techknowlogick techknowlogick added this to the 1.16.0 milestone Oct 8, 2021
@techknowlogick techknowlogick marked this pull request as draft October 8, 2021 19:11
@codecov-commenter

This comment has been minimized.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 8, 2021
@techknowlogick techknowlogick marked this pull request as ready for review October 8, 2021 21:42
snapPath := os.Getenv("SNAP")
if snapPath != "" && strings.HasPrefix(appPath, snapPath) {
revision := os.Getenv("SNAP_REVISION")
appPath = strings.Replace(appPath, revision, "current", 1)
Copy link
Contributor

@wxiaoguang wxiaoguang Oct 9, 2021

Choose a reason for hiding this comment

The 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.

Copy link

@OleHusgaard OleHusgaard Oct 9, 2021

Choose a reason for hiding this comment

The 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.

@@ -51,6 +52,8 @@ For documentation about each of the variables available, refer to the
- `USER`: System user that Gitea will run as. Used for some repository access strings.
- `USERNAME`: if no `USER` found, Gitea will use `USERNAME`
- `HOME`: User home directory path. The `USERPROFILE` environment variable is used in Windows.
- `SNAP`: Path to directory that snap uses to store Gitea's configuration. Snap defaults to using `$GITEA_APP_PATH`.
- `SNAP_REVISION`: If Gitea is installed using snap, revision number of snap in use.
Copy link
Contributor

@wxiaoguang wxiaoguang Oct 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SNAP and SNAP_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.

@6543
Copy link
Member

6543 commented Oct 12, 2021

in terms of hacktoberfest i think it would not count for OleHusgaard ... but you could push final version of this pull HEAD back to his HEAD ... or I could do so ;) etc...

@techknowlogick
Copy link
Member Author

@6543 it wouldn't count because the other PR was made before oct1

@6543
Copy link
Member

6543 commented Oct 12, 2021

oh ... ok then it doesnt matter :D

@wxiaoguang
Copy link
Contributor

Hey, I just have a new idea about this problem. Why should we spend so much time on guessing the gitea binary path inside snap ....

Can't we just check and update the repository's hooks on every push? As long as every git push changes many files, we check two or three hook files it doesn't cost much. Once we can make sure the content of the hooks are correct, we do not need to guess the snap path.

@wxiaoguang
Copy link
Contributor

The new idea is implemented in #17335 , I think the new PR can fully resolve the problem

@lunny
Copy link
Member

lunny commented Nov 15, 2021

@techknowlogick Could you confirm that #17335 replaced this PR.

@techknowlogick techknowlogick removed this from the 1.16.0 milestone Nov 18, 2021
@techknowlogick techknowlogick deleted the snap-fix branch November 18, 2021 07:17
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gitea Snap update issue
8 participants