-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not allow different storage configurations to point to the same directory #30169
Conversation
Compare by ignoring spaces: https://github.com/go-gitea/gitea/pull/30169/files?diff=split&w=1 |
8dc3257
to
ce64832
Compare
@@ -58,7 +58,7 @@ func loadIndexerFrom(rootCfg ConfigProvider) { | |||
if !filepath.IsAbs(Indexer.IssuePath) { | |||
Indexer.IssuePath = filepath.ToSlash(filepath.Join(AppWorkPath, Indexer.IssuePath)) | |||
} | |||
fatalDuplicatedPath("issue_indexer", Indexer.IssuePath) | |||
checkOverlappedPath("indexer.ISSUE_INDEXER_PATH", Indexer.IssuePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better if we notify the users explicitly what the section is:
checkOverlappedPath("indexer.ISSUE_INDEXER_PATH", Indexer.IssuePath) | |
checkOverlappedPath("[indexer].ISSUE_INDEXER_PATH", Indexer.IssuePath) |
@@ -286,7 +286,7 @@ func loadRepositoryFrom(rootCfg ConfigProvider) { | |||
RepoRootPath = filepath.Clean(RepoRootPath) | |||
} | |||
|
|||
fatalDuplicatedPath("repository.ROOT", RepoRootPath) | |||
checkOverlappedPath("repository.ROOT", RepoRootPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkOverlappedPath("repository.ROOT", RepoRootPath) | |
checkOverlappedPath("[repository].ROOT", RepoRootPath) |
@@ -240,7 +240,7 @@ func getStorageForLocal(targetSec, overrideSec ConfigSection, tp targetSecType, | |||
} | |||
} | |||
|
|||
fatalDuplicatedPath("storage."+name, storage.Path) | |||
checkOverlappedPath("storage."+name+".PATH", storage.Path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkOverlappedPath("storage."+name+".PATH", storage.Path) | |
checkOverlappedPath("[storage."+name+"].PATH", storage.Path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not right by your approach. [storage.xxx]
is the section name. [storage]
is not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, fixed my comment
@@ -46,7 +46,7 @@ func loadSessionFrom(rootCfg ConfigProvider) { | |||
SessionConfig.ProviderConfig = strings.Trim(sec.Key("PROVIDER_CONFIG").MustString(filepath.Join(AppDataPath, "sessions")), "\" ") | |||
if SessionConfig.Provider == "file" && !filepath.IsAbs(SessionConfig.ProviderConfig) { | |||
SessionConfig.ProviderConfig = filepath.Join(AppWorkPath, SessionConfig.ProviderConfig) | |||
fatalDuplicatedPath("session", SessionConfig.ProviderConfig) | |||
checkOverlappedPath("session.PROVIDER_CONFIG", SessionConfig.ProviderConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkOverlappedPath("session.PROVIDER_CONFIG", SessionConfig.ProviderConfig) | |
checkOverlappedPath("[session].PROVIDER_CONFIG", SessionConfig.ProviderConfig) |
// TODO: some paths shouldn't overlap (storage.xxx.path), while some could (data path is the base path for storage path) | ||
if targetName, ok := configuredPaths[path]; ok && targetName != name { | ||
msg := fmt.Sprintf("Configured path %q is used by %q and %q at the same time. The paths must be unique to prevent data loss.", path, targetName, name) | ||
log.Error("%s", msg) | ||
DeprecatedWarnings = append(DeprecatedWarnings, msg) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we fix this completely using
// TODO: some paths shouldn't overlap (storage.xxx.path), while some could (data path is the base path for storage path) | |
if targetName, ok := configuredPaths[path]; ok && targetName != name { | |
msg := fmt.Sprintf("Configured path %q is used by %q and %q at the same time. The paths must be unique to prevent data loss.", path, targetName, name) | |
log.Error("%s", msg) | |
DeprecatedWarnings = append(DeprecatedWarnings, msg) | |
} | |
path = gopath.Clean(path) | |
for existingPath, existingName := range configuredPaths { | |
if strings.HasPrefix(path, existingPath) || strings.HasPrefix(existingPath, path) { | |
var msg string | |
if path == existingPath { | |
msg = fmt.Sprintf("Path %q is used by %q and %q simultaneously. This may lead to data loss. To prevent this, the paths must be different and they must not overlap.", path, existingName, name) | |
} else { | |
msg = fmt.Sprintf("Path %q (used by %q) is contained within %q (used by %q). This may lead to data loss. To prevent this, the paths may not overlap.", existingPath, existingName, path, name) | |
} | |
log.Error("%s", msg) | |
DeprecatedWarnings = append(DeprecatedWarnings, msg) | |
} |
(assuming we have an import gopath path
above)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not right (incomplete). /a/b
overlaps /a
, meanwhile /a
overlaps /a/b
If you would like to "complete" it, it also needs enough tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, fixed my comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But your "msg" is still not right, and it doesn't have tests.
As I said: "I won't do any further change". So feel free to take it, or improve it, or discard it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And one more thing, path = gopath.Clean(path)
is also not right. It should use filepath
.
|
||
EnableGzip = sec.Key("ENABLE_GZIP").MustBool() | ||
EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false) | ||
PprofDataPath = sec.Key("PPROF_DATA_PATH").MustString(filepath.Join(AppWorkPath, "data/tmp/pprof")) | ||
if !filepath.IsAbs(PprofDataPath) { | ||
PprofDataPath = filepath.Join(AppWorkPath, PprofDataPath) | ||
} | ||
fatalDuplicatedPath("pprof_data_path", PprofDataPath) | ||
checkOverlappedPath("server.PPROF_DATA_PATH", PprofDataPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkOverlappedPath("server.PPROF_DATA_PATH", PprofDataPath) | |
checkOverlappedPath("[server].PPROF_DATA_PATH", PprofDataPath) |
This is one more time that I have to fix other's bugs because nobody listened to my suggestions. So I have no patience or motivation to make any more change. Feel free to do what people like, take it, or improve it, or discard it. |
@wxiaoguang If I'm not mistaken, my proposed change will fix the problem completely. |
OK, I managed to reply the suggestions as much as possible, there are more problems than this PR. As I said, I do not have motivation to do any further change because the old approach just doesn't look good to me and this PR only helps to avoid some serious buggy behaviors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then let's get this PR merged now, and I'll see that I improve it afterwards.
The current state is better than nothing although not perfect.
…rectory (#30169) (#30204) Backport #30169 by wxiaoguang Replace #29171 Co-authored-by: wxiaoguang <[email protected]>
* giteaofficial/main: Do not allow different storage configurations to point to the same directory (go-gitea#30169) Fix GPG subkey verify (go-gitea#30193) [skip ci] Updated translations via Crowdin Fix unclickable checkboxes (go-gitea#30195) Remove jQuery class from the issue author dropdown (go-gitea#30188) Remove jQuery class from the comment edit history (go-gitea#30186) Remove jQuery class from the repository branch settings (go-gitea#30184) [skip ci] Updated translations via Crowdin Use Crowdin action for translation sync (go-gitea#30054) Remove jQuery class from the project page (go-gitea#30183) Remove jQuery class from the comment context menu (go-gitea#30179)
Replace #29171