You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/modules
wxiaoguang 061b68e995
Refactor path & config system (#25330) (#25416)
Backport #25330

# The problem

There were many "path tricks":

* By default, Gitea uses its program directory as its work path
* Gitea tries to use the "work path" to guess its "custom path" and
"custom conf (app.ini)"
* Users might want to use other directories as work path
* The non-default work path should be passed to Gitea by GITEA_WORK_DIR
or "--work-path"
* But some Gitea processes are started without these values
    * The "serv" process started by OpenSSH server
    * The CLI sub-commands started by site admin
* The paths are guessed by SetCustomPathAndConf again and again
* The default values of "work path / custom path / custom conf" can be
changed when compiling

# The solution

* Use `InitWorkPathAndCommonConfig` to handle these path tricks, and use
test code to cover its behaviors.
* When Gitea's web server runs, write the WORK_PATH to "app.ini", this
value must be the most correct one, because if this value is not right,
users would find that the web UI doesn't work and then they should be
able to fix it.
* Then all other sub-commands can use the WORK_PATH in app.ini to
initialize their paths.
* By the way, when Gitea starts for git protocol, it shouldn't output
any log, otherwise the git protocol gets broken and client blocks
forever.

The "work path" priority is: WORK_PATH in app.ini > cmd arg --work-path
> env var GITEA_WORK_DIR > builtin default

The "app.ini" searching order is: cmd arg --config > cmd arg "work path
/ custom path" > env var "work path / custom path" > builtin default


## ⚠️ BREAKING

If your instance's "work path / custom path / custom conf" doesn't meet
the requirements (eg: work path must be absolute), Gitea will report a
fatal error and exit. You need to set these values according to the
error log.
2 years ago
..
actions Use the type RefName for all the needed places and fix pull mirror sync bugs (#24634) 2 years ago
activitypub Add Chef package registry (#22554) 2 years ago
analyze Implement FSFE REUSE for golang files (#21840) 2 years ago
assetfs Use a general approach to access custom/static/builtin assets (#24022) 2 years ago
auth Use a general approach to access custom/static/builtin assets (#24022) 2 years ago
avatar Improve avatar uploading / resizing / compressing, remove Fomantic card module (#24653) 2 years ago
base Use a general Eval function for expressions in templates. (#23927) 2 years ago
cache Update redis library to support redis v7 (#24114) 2 years ago
charset Update go tool dependencies, restructure lint targets (#24239) 2 years ago
container Implement FSFE REUSE for golang files (#21840) 2 years ago
context Fix open redirect check for more cases (#25143) (#25154) 2 years ago
csv Refactor locale number (#24134) 2 years ago
doctor Refactor path & config system (#25330) (#25416) 2 years ago
emoji Fix unstable emoji sort (#22346) 2 years ago
eventsource Move `convert` package to services (#22264) 2 years ago
generate Implement FSFE REUSE for golang files (#21840) 2 years ago
git Fix index generation parallelly failure (#25235) (#25269) 2 years ago
gitgraph Add context cache as a request level cache (#22294) 2 years ago
graceful Improve queue and logger context (#24924) 2 years ago
hcaptcha Consume hcaptcha and pwn deps (#22610) 2 years ago
highlight test_env: hardcode major go version in use (#23464) 2 years ago
hostmatcher Implement FSFE REUSE for golang files (#21840) 2 years ago
html Implement FSFE REUSE for golang files (#21840) 2 years ago
httpcache Use standard HTTP library to serve files (#24693) 2 years ago
httplib Use standard HTTP library to serve files (#24693) 2 years ago
indexer Improve queue and logger context (#24924) 2 years ago
issue/template Allow issue templates to not render title (#22589) 2 years ago
json Update gitea-vet to check FSFE REUSE (#22004) 2 years ago
label Make label templates have consistent behavior and priority (#23749) 2 years ago
lfs Rewrite logger system (#24726) 2 years ago
log Improve logger Pause handling (#24946) 2 years ago
markup Refactor path & config system (#25330) (#25416) 2 years ago
mcaptcha Implement FSFE REUSE for golang files (#21840) 2 years ago
metrics Use a separate admin page to show global stats, remove `actions` stat (#25062) 2 years ago
migration Scoped labels (#22585) 2 years ago
mirror Improve queue and logger context (#24924) 2 years ago
nosql Update redis library to support redis v7 (#24114) 2 years ago
notification Rename NotifyPullReviewRequest to NotifyPullRequestReviewRequest (#24988) 2 years ago
options Use a general approach to access custom/static/builtin assets (#24022) 2 years ago
packages Add CRAN package registry (#22331) 2 years ago
paginator Use more specific test methods (#24265) 2 years ago
pprof Implement FSFE REUSE for golang files (#21840) 2 years ago
private Use the type RefName for all the needed places and fix pull mirror sync bugs (#24634) 2 years ago
process Do not output "Trace" level logs from process manager by default (#24952) 2 years ago
proxy Use proxy for pull mirror (#22771) 2 years ago
proxyprotocol Implement FSFE REUSE for golang files (#21840) 2 years ago
public Use standard HTTP library to serve files (#24693) 2 years ago
queue Help to recover from corrupted levelqueue (#24912) 2 years ago
recaptcha Implement FSFE REUSE for golang files (#21840) 2 years ago
references Use correct captured group range when parsing cross-reference (#22672) 2 years ago
regexplru Implement FSFE REUSE for golang files (#21840) 2 years ago
repository Remove stars when repo goes private (#19904) 2 years ago
secret Improve decryption failure message (#24573) 2 years ago
session Update redis library to support redis v7 (#24114) 2 years ago
setting Refactor path & config system (#25330) (#25416) 2 years ago
sitemap Fix sitemap (#22272) 2 years ago
ssh Fix incorrect config argument position for builtin SSH server (#25341) 2 years ago
storage Fix all possible setting error related storages and added some tests (#23911) (#25244) 2 years ago
structs Fix `Permission` in API returned repository struct (#25388) (#25441) 2 years ago
svg Use inline SVG for built-in OAuth providers (#25171) (#25234) 2 years ago
sync Implement FSFE REUSE for golang files (#21840) 2 years ago
system Implement FSFE REUSE for golang files (#21840) 2 years ago
templates Fix missing commit message body when the message has leading newlines (#25418) (#25422) 2 years ago
test Fix admin config page error, use tests to cover the admin config and 500 error page (#24965) 2 years ago
testlogger Refactor path & config system (#25330) (#25416) 2 years ago
timeutil Fix incorrect webhook time and use relative-time to display it (#24477) 2 years ago
translation Refactor INI package (first step) (#25024) 2 years ago
turnstile Add new captcha: cloudflare turnstile (#22369) 2 years ago
typesniffer Do not recognize text files as audio (#23355) 2 years ago
updatechecker Implement FSFE REUSE for golang files (#21840) 2 years ago
upload Implement FSFE REUSE for golang files (#21840) 2 years ago
uri Implement FSFE REUSE for golang files (#21840) 2 years ago
user Implement FSFE REUSE for golang files (#21840) 2 years ago
util Move some regexp out of functions (#25430) (#25445) 2 years ago
validation Map OIDC groups to Orgs/Teams (#21441) 2 years ago
web Fix install page context, make the install page tests really test (#24858) 2 years ago
webhook New webhook trigger for receiving Pull Request review requests (#24481) 2 years ago