Skip to content

Commit 14a8a0e

Browse files
committed
move function
1 parent 0e2b59d commit 14a8a0e

File tree

2 files changed

+30
-39
lines changed

2 files changed

+30
-39
lines changed

modules/setting/directory.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

modules/setting/setting.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,36 @@ func SetCustomPathAndConf(providedCustom, providedConf, providedWorkPath string)
186186
}
187187
}
188188

189+
// PrepareAppDataPath creates app data directory if necessary
190+
func PrepareAppDataPath() error {
191+
// FIXME: There are too many calls to MkdirAll in old code. It is incorrect.
192+
// For example, if someDir=/mnt/vol1/gitea-home/data, if the mount point /mnt/vol1 is not mounted when Gitea runs,
193+
// then gitea will make new empty directories in /mnt/vol1, all are stored in the root filesystem.
194+
// The correct behavior should be: creating parent directories is end users' duty. We only create sub-directories in existing parent directories.
195+
// For quickstart, the parent directories should be created automatically for first startup (eg: a flag or a check of INSTALL_LOCK).
196+
// 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.
197+
198+
st, err := os.Stat(AppDataPath)
199+
200+
if os.IsNotExist(err) {
201+
err = os.MkdirAll(AppDataPath, os.ModePerm)
202+
if err != nil {
203+
return fmt.Errorf("unable to create the APP_DATA_PATH directory: %q, Error: %w", AppDataPath, err)
204+
}
205+
return nil
206+
}
207+
208+
if err != nil {
209+
return fmt.Errorf("unable to use APP_DATA_PATH %q. Error: %w", AppDataPath, err)
210+
}
211+
212+
if !st.IsDir() /* also works for symlink */ {
213+
return fmt.Errorf("the APP_DATA_PATH %q is not a directory (or symlink to a directory) and can't be used", AppDataPath)
214+
}
215+
216+
return nil
217+
}
218+
189219
// LoadFromExisting initializes setting options from an existing config file (app.ini)
190220
func LoadFromExisting() {
191221
loadFromConf(false, "")

0 commit comments

Comments
 (0)