diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-10-21 17:22:43 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-21 17:22:43 +0800 |
commit | 83df0caf15c4a8c3b9336987f329501507c6d527 (patch) | |
tree | 34fa87145972771c6d3ea417bba79028e3186b70 /modules/setting | |
parent | 053b2f4dce2c404bcd7cb828147deb4b99ab71e6 (diff) | |
download | gitea-83df0caf15c4a8c3b9336987f329501507c6d527.tar.gz gitea-83df0caf15c4a8c3b9336987f329501507c6d527.zip |
Sync gitea app path for git hooks and authorized keys when starting (#17335)
Gitea writes its own AppPath into git hook scripts. If Gitea's AppPath changes, then the git push will fail.
This PR:
* Introduce an AppState module, it can persist app states into database
* During GlobalInit, Gitea will check if the current AppPath is the same as last one. If they don't match, Gitea will sync git hooks.
* Refactor some code to make them more clear.
* Also, "Detect if gitea binary's name changed" #11341 is related, we call models.RewriteAllPublicKeys to update ssh authorized_keys file
Diffstat (limited to 'modules/setting')
-rw-r--r-- | modules/setting/setting.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/modules/setting/setting.go b/modules/setting/setting.go index a1ac090e46..c5608c85bc 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -683,6 +683,18 @@ func NewContext() { StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(StaticRootPath) StaticCacheTime = sec.Key("STATIC_CACHE_TIME").MustDuration(6 * time.Hour) AppDataPath = sec.Key("APP_DATA_PATH").MustString(path.Join(AppWorkPath, "data")) + if _, err = os.Stat(AppDataPath); err != nil { + // FIXME: There are too many calls to MkdirAll in old code. It is incorrect. + // For example, if someDir=/mnt/vol1/gitea-home/data, if the mount point /mnt/vol1 is not mounted when Gitea runs, + // then gitea will make new empty directories in /mnt/vol1, all are stored in the root filesystem. + // The correct behavior should be: creating parent directories is end users' duty. We only create sub-directories in existing parent directories. + // For quickstart, the parent directories should be created automatically for first startup (eg: a flag or a check of INSTALL_LOCK). + // Now we can take the first step to do correctly (using Mkdir) in other packages, and prepare the AppDataPath here, then make a refactor in future. + err = os.MkdirAll(AppDataPath, os.ModePerm) + if err != nil { + log.Fatal("Failed to create the directory for app data path '%s'", AppDataPath) + } + } EnableGzip = sec.Key("ENABLE_GZIP").MustBool() EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false) PprofDataPath = sec.Key("PPROF_DATA_PATH").MustString(path.Join(AppWorkPath, "data/tmp/pprof")) |