From 78393aea4f5bc860e22a27ad50e9297706216622 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Mon, 7 Aug 2023 14:53:15 -0500 Subject: [PATCH 1/5] feat: storage paths must be unique Signed-off-by: jolheiser --- modules/setting/storage.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/setting/storage.go b/modules/setting/storage.go index c28f2be4ed714..6c4481143700e 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) { @@ -220,5 +222,10 @@ 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.", storage.Path, storageTarget, name, storageTarget, name) + } + storagePaths[storage.Path] = name + return &storage, nil } From 18108a4cffbb9c9672a36907d5c8d64dc1cc8011 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Mon, 7 Aug 2023 15:01:02 -0500 Subject: [PATCH 2/5] chore: add PR to log Signed-off-by: jolheiser --- modules/setting/storage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/setting/storage.go b/modules/setting/storage.go index 6c4481143700e..e33d2c220e718 100644 --- a/modules/setting/storage.go +++ b/modules/setting/storage.go @@ -223,7 +223,7 @@ 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.", storage.Path, storageTarget, name, 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/26271 and the issue it fixes.", storage.Path, storageTarget, name, storageTarget, name) } storagePaths[storage.Path] = name From 8e286865dabc0e42537d76de1849ab527baf9a64 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Mon, 7 Aug 2023 15:04:25 -0500 Subject: [PATCH 3/5] chore: reference own PR Signed-off-by: jolheiser --- modules/setting/storage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/setting/storage.go b/modules/setting/storage.go index e33d2c220e718..ab61ff8027ddc 100644 --- a/modules/setting/storage.go +++ b/modules/setting/storage.go @@ -223,7 +223,7 @@ 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/26271 and the issue it fixes.", storage.Path, storageTarget, name, 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 From 096119244a0fabf45afd4f7d42da781d5462f7b4 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Mon, 7 Aug 2023 15:19:13 -0500 Subject: [PATCH 4/5] chore: appease linter Signed-off-by: jolheiser --- modules/setting/storage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/setting/storage.go b/modules/setting/storage.go index ab61ff8027ddc..a4d265398a834 100644 --- a/modules/setting/storage.go +++ b/modules/setting/storage.go @@ -223,7 +223,7 @@ 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) + 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 From a9a361bf8e3328ff4ede88309d2b37583d328cab Mon Sep 17 00:00:00 2001 From: jolheiser Date: Mon, 7 Aug 2023 21:45:16 -0500 Subject: [PATCH 5/5] fix: only unique for local storage Signed-off-by: jolheiser --- modules/setting/storage.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/setting/storage.go b/modules/setting/storage.go index a4d265398a834..7011f93224bbb 100644 --- a/modules/setting/storage.go +++ b/modules/setting/storage.go @@ -208,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) @@ -222,10 +227,5 @@ 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 - return &storage, nil }