Skip to content

Commit 9e06309

Browse files
committed
fix
1 parent fd4c82e commit 9e06309

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

modules/setting/setting.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,18 @@ func NewContext() {
687687
StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(StaticRootPath)
688688
StaticCacheTime = sec.Key("STATIC_CACHE_TIME").MustDuration(6 * time.Hour)
689689
AppDataPath = sec.Key("APP_DATA_PATH").MustString(path.Join(AppWorkPath, "data"))
690+
if _, err = os.Stat(AppDataPath); err != nil {
691+
// FIXME: Many calls to MkdirAll are using 0644 (not executable) or `os.ModePerm`(0o777, world-wide writable), which are incorrect.
692+
// FIXME: There are too many calls to MkdirAll in old code. It is incorrect.
693+
// For example, if someDir=/mnt/vol1/gitea-home/data, if the mount point /mnt/vol1 is not mounted when Gitea runs,
694+
// then gitea will make new empty directories in /mnt/vol1, all are stored in the root filesystem.
695+
// The correct behavior should be: creating parent directories is end users' duty. We only create sub-directories in existing parent directories.
696+
// Now we can take the first step to do correctly (Mkdir) in other packages, and prepare the AppDataPath here, then make a refactor in future.
697+
err = os.MkdirAll(AppDataPath, os.FileMode(0755))
698+
if err != nil {
699+
log.Fatal("Failed to create the directory for app data path '%s'", AppDataPath)
700+
}
701+
}
690702
EnableGzip = sec.Key("ENABLE_GZIP").MustBool()
691703
EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false)
692704
PprofDataPath = sec.Key("PPROF_DATA_PATH").MustString(path.Join(AppWorkPath, "data/tmp/pprof"))

routers/init.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func guaranteeInit(fn func() error) {
5454
if err != nil {
5555
ptr := reflect.ValueOf(fn).Pointer()
5656
fi := runtime.FuncForPC(ptr)
57-
log.Fatal("%s init failed: %v", fi.Name(), err)
57+
log.Fatal("%s failed: %v", fi.Name(), err)
5858
}
5959
}
6060

@@ -63,7 +63,7 @@ func guaranteeInitCtx(ctx context.Context, fn func(ctx context.Context) error) {
6363
if err != nil {
6464
ptr := reflect.ValueOf(fn).Pointer()
6565
fi := runtime.FuncForPC(ptr)
66-
log.Fatal("%s(ctx) init failed: %v", fi.Name(), err)
66+
log.Fatal("%s(ctx) failed: %v", fi.Name(), err)
6767
}
6868
}
6969

@@ -80,10 +80,12 @@ func syncAppPathForGit(ctx context.Context) (err error) {
8080
return err
8181
}
8282
if runtimeState.LastAppPath != setting.AppPath {
83-
log.Info("AppPath changed from '%s' to '%s', sync repository hooks ...", runtimeState.LastAppPath, setting.AppPath)
83+
log.Info("AppPath changed from '%s' to '%s'", runtimeState.LastAppPath, setting.AppPath)
84+
85+
log.Info("re-sync repository hooks ...")
8486
guaranteeInitCtx(ctx, repo_module.SyncRepositoryHooks)
8587

86-
log.Info("AppPath changed from '%s' to '%s', sync ssh keys ...", runtimeState.LastAppPath, setting.AppPath)
88+
log.Info("re-write ssh public keys ...")
8789
guaranteeInit(models.RewriteAllPublicKeys)
8890

8991
runtimeState.LastAppPath = setting.AppPath

0 commit comments

Comments
 (0)