Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions modules/setting/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,17 @@ func getStorage(rootCfg ConfigProvider, name, typ string, sec ConfigSection) (*S
targetPath := ConfigSectionKeyString(targetSec, "PATH", "")
if targetPath == "" {
targetPath = AppDataPath
} else if !filepath.IsAbs(targetPath) {
targetPath = filepath.Join(AppDataPath, targetPath)
}

if extraConfigSec == nil {
storage.Path = filepath.Join(targetPath, name)
} else {
storage.Path = ConfigSectionKeyString(extraConfigSec, "PATH", filepath.Join(targetPath, name))
}

if !filepath.IsAbs(storage.Path) {
storage.Path = filepath.Join(AppWorkPath, storage.Path)
if !filepath.IsAbs(storage.Path) {
storage.Path = filepath.Join(AppDataPath, storage.Path)
}
}

case string(MinioStorageType):
Expand Down
33 changes: 33 additions & 0 deletions modules/setting/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,39 @@ PATH = /data/gitea
assert.EqualValues(t, "/data/gitea/repo-avatars", RepoAvatar.Storage.Path)
}

func Test_getStorageInheritStorageTypeLocalRelativePath(t *testing.T) {
iniStr := `
[storage]
STORAGE_TYPE = local
PATH = storages
`
cfg, err := NewConfigProviderFromData(iniStr)
assert.NoError(t, err)

assert.NoError(t, loadPackagesFrom(cfg))
assert.EqualValues(t, "local", Packages.Storage.Type)
assert.EqualValues(t, filepath.Join(AppDataPath, "storages", "packages"), Packages.Storage.Path)

assert.NoError(t, loadRepoArchiveFrom(cfg))
assert.EqualValues(t, "local", RepoArchive.Storage.Type)
assert.EqualValues(t, filepath.Join(AppDataPath, "storages", "repo-archive"), RepoArchive.Storage.Path)

assert.NoError(t, loadActionsFrom(cfg))
assert.EqualValues(t, "local", Actions.LogStorage.Type)
assert.EqualValues(t, filepath.Join(AppDataPath, "storages", "actions_log"), Actions.LogStorage.Path)

assert.EqualValues(t, "local", Actions.ArtifactStorage.Type)
assert.EqualValues(t, filepath.Join(AppDataPath, "storages", "actions_artifacts"), Actions.ArtifactStorage.Path)

assert.NoError(t, loadAvatarsFrom(cfg))
assert.EqualValues(t, "local", Avatar.Storage.Type)
assert.EqualValues(t, filepath.Join(AppDataPath, "storages", "avatars"), Avatar.Storage.Path)

assert.NoError(t, loadRepoAvatarFrom(cfg))
assert.EqualValues(t, "local", RepoAvatar.Storage.Type)
assert.EqualValues(t, filepath.Join(AppDataPath, "storages", "repo-avatars"), RepoAvatar.Storage.Path)
}

func Test_getStorageInheritStorageTypeLocalPathOverride(t *testing.T) {
iniStr := `
[storage]
Expand Down