-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: 删除目录校验 #7035
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
fix: 删除目录校验 #7035
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
| if filepath.Base(op.Path) == ".1panel_clash" || op.Path == excludeDir { | ||
| return buserr.New(constant.ErrPathNotDelete) | ||
| } | ||
| } |
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.
这段Go代码的主要问题在于file.Delete()方法,当op是目录时需要处理的情况。目前,在逻辑上删除目录操作可能不符合预期:
func (f *FileService) Delete(op request.FileDelete) error {
if op.IsDir && !strings.Contains(global.CONF.System.DataDir, op.Path) { // 这行如果删除的是某个包含'.1panel_clash' 的路径或与系统默认数据目录的路径相同,则会导致逻辑错误。
return buserr.New(constant.ErrPathNotDelete)
}
...这个逻辑可能导致某些特定情况下的文件被误删,如.1panel_clash的存在导致正常情况下会忽略但最后还是被删除。
建议调整为:
- 删除单个非空目录:
func (f *FileService) Delete(op request.FileDelete) error {
if !filepath.Walk(op.Path).Contains(".") {
return f.fileExistCheck(op.Path) // 如果不存在点则继续往下
}
err := f.deleteDirectory(op.Path)
if err != nil {
return err
}
Comment: suggestion func (f *FileService) Delete(op request.FileDelete) error { if !filepath.Walk(op.Path).Contains('.') { ... } else {
这样可以避免因为路径存在指定文件和排除路径而意外执行错误的操作了。
|
wanghe-fit2cloud
left a 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.
/lgtm
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wanghe-fit2cloud The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |



No description provided.