Skip to content

Conversation

@lan-yonghui
Copy link
Member

No description provided.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Nov 13, 2024

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.

Details

Instructions 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)
}
}

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的存在导致正常情况下会忽略但最后还是被删除。

建议调整为:

  1. 删除单个非空目录:

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 {

这样可以避免因为路径存在指定文件和排除路径而意外执行错误的操作了。

@1Panel-bot 1Panel-bot added the dev label Nov 13, 2024
@sonarqubecloud
Copy link

Copy link
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@wanghe-fit2cloud
Copy link
Member

/approve

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Nov 13, 2024

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot merged commit 4c01b1e into dev Nov 13, 2024
5 checks passed
@f2c-ci-robot f2c-ci-robot bot deleted the pr@dev@fix_dir_del branch November 13, 2024 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants