diff --git a/modules/setting/storage.go b/modules/setting/storage.go index c28f2be4ed714..7011f93224bbb 100644 --- a/modules/setting/storage.go +++ b/modules/setting/storage.go @@ -84,6 +84,8 @@ func getDefaultStorageSection(rootCfg ConfigProvider) ConfigSection { return storageSec } +var storagePaths = make(map[string]string) + // getStorage will find target section and extra special section first and then read override // items from extra section func getStorage(rootCfg ConfigProvider, name, typ string, sec ConfigSection) (*Storage, error) { @@ -206,6 +208,11 @@ func getStorage(rootCfg ConfigProvider, name, typ string, sec ConfigSection) (*S } } + if storageTarget, ok := storagePaths[storage.Path]; ok && storageTarget != name { + return nil, fmt.Errorf("storage path %q is being used by %q and %q and all storage paths must be unique to prevent data loss. Please set [storage.%s].PATH and [storage.%s].PATH to unique paths. For more information, see https://github.com/go-gitea/gitea/pull/26380", storage.Path, storageTarget, name, storageTarget, name) + } + storagePaths[storage.Path] = name + case string(MinioStorageType): if err := targetSec.MapTo(&storage.MinioConfig); err != nil { return nil, fmt.Errorf("map minio config failed: %v", err)