Skip to content

Commit 16c1597

Browse files
Fix AppDataPath related Issue
1 parent c80ff4e commit 16c1597

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

custom/conf/app.ini.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,6 @@ TOKEN =
795795

796796
[storage]
797797
; URL of Bucket where files, such as, attachments, avatars, etc. are stored
798-
; If unset, file://<current_directory> is used to maintain backward compatibility
798+
; If unset, file://<AppWorkPath> is used to maintain backward compatibility
799799
; Consult https://gocloud.dev/howto/blob/ for URL format for various cloud providers
800800
BUCKET_URL =

modules/setting/setting.go

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ const (
7373
// settings
7474
var (
7575
// AppVer settings
76-
AppVer string
77-
AppBuiltWith string
78-
AppName string
79-
AppURL string
80-
AppSubURL string
81-
AppSubURLDepth int // Number of slashes
82-
AppPath string
83-
AppDataPath string
84-
AppWorkPath string
76+
AppVer string
77+
AppBuiltWith string
78+
AppName string
79+
AppURL string
80+
AppSubURL string
81+
AppSubURLDepth int // Number of slashes
82+
AppPath string
83+
AppDataPath string
84+
appDataUserPath string
85+
AppWorkPath string
8586

8687
// Server settings
8788
Protocol Scheme
@@ -701,7 +702,7 @@ func NewContext() {
701702
if err = sec.MapTo(&LFS); err != nil {
702703
log.Fatal("Failed to map LFS settings: %v", err)
703704
}
704-
LFS.ContentPath = sec.Key("LFS_CONTENT_PATH").MustString(filepath.Join("data", "lfs"))
705+
LFS.ContentPath = sec.Key("LFS_CONTENT_PATH").MustString(filepath.Join(appDataUserPath, "lfs"))
705706
forcePathSeparator(LFS.ContentPath)
706707
LFS.ContentPath = suffixPathSeparator(LFS.ContentPath)
707708

@@ -865,10 +866,10 @@ func NewContext() {
865866
newRepository()
866867

867868
sec = Cfg.Section("picture")
868-
AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString(path.Join("data", "avatars"))
869+
AvatarUploadPath = sec.Key("AVATAR_UPLOAD_PATH").MustString(path.Join(appDataUserPath, "avatars"))
869870
forcePathSeparator(AvatarUploadPath)
870871
AvatarUploadPath = suffixPathSeparator(AvatarUploadPath)
871-
RepositoryAvatarUploadPath = sec.Key("REPOSITORY_AVATAR_UPLOAD_PATH").MustString(path.Join("data", "repo-avatars"))
872+
RepositoryAvatarUploadPath = sec.Key("REPOSITORY_AVATAR_UPLOAD_PATH").MustString(path.Join(appDataUserPath, "repo-avatars"))
872873
forcePathSeparator(RepositoryAvatarUploadPath)
873874
RepositoryAvatarUploadPath = suffixPathSeparator(RepositoryAvatarUploadPath)
874875
RepositoryAvatarFallback = sec.Key("REPOSITORY_AVATAR_FALLBACK").MustString("none")
@@ -1049,6 +1050,38 @@ func loadOrGenerateInternalToken(sec *ini.Section) string {
10491050
return token
10501051
}
10511052

1053+
/*
1054+
- Path represents AttachmentPath, AvatarUploadPath, RepositoryAvatarUploadPath or LFS.ContentPath
1055+
- corresponding default PathValues are : "attachments", "avatars", "repo-avatars" & "lfs"
1056+
1057+
- appDataUserPath defaults to "data"
1058+
1059+
There may be two scenarios:
1060+
1061+
s1:
1062+
Path is set in app.ini (rel or abs)
1063+
1064+
s2:
1065+
Path is unset in app.ini
1066+
Path <= appDataUserPath + Path
1067+
1068+
If appDataUserPath is set to abs in app.ini (via APP_DATA_PATH)
1069+
Path is abs
1070+
Otherwise
1071+
Path is rel
1072+
1073+
1074+
If Path is abs, the files will be read or stored to that abs Path even if the BUCKET_URL is set.
1075+
Otherwise the following occurs,
1076+
1077+
if BUCKET_URL NOT SET {
1078+
Path = file://{AppWorkPath}/{Path}
1079+
} else {
1080+
Path is used as Bucket prefix
1081+
}
1082+
1083+
*/
1084+
10521085
// OpenBucket returns the bucket associated to path parameter
10531086
func OpenBucket(ctx context.Context, path string) (*blob.Bucket, error) {
10541087
if filepath.IsAbs(path) {

0 commit comments

Comments
 (0)