@@ -186,6 +186,36 @@ func SetCustomPathAndConf(providedCustom, providedConf, providedWorkPath string)
186
186
}
187
187
}
188
188
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
+
189
219
// LoadFromExisting initializes setting options from an existing config file (app.ini)
190
220
func LoadFromExisting () {
191
221
loadFromConf (false , "" )
0 commit comments