Skip to content

fix(aliyundrive_open): resolve file duplication issues and improve path handling#8358

Merged
xhofe merged 3 commits intoAlistGo:mainfrom
gaoyifan:main
Apr 19, 2025
Merged

fix(aliyundrive_open): resolve file duplication issues and improve path handling#8358
xhofe merged 3 commits intoAlistGo:mainfrom
gaoyifan:main

Conversation

@gaoyifan
Copy link
Copy Markdown
Contributor

建议来自 #7962 (comment)

本次提交解决了阿里云盘开放接口驱动中的几个问题:

  1. 通过实现新的removeDuplicateFiles方法清理操作后的重复文件,修复文件重复问题
  2. 将移动操作的check_name_mode从"refuse"改为"ignore",允许在目标目录存在同名文件时进行移动
  3. 设置复制操作在成功复制后处理重复文件
  4. 改进所有文件操作(移动、重命名、上传、创建目录)的路径处理,正确维护对象的完整路径
  5. 实现GetRoot接口,使根对象能够正确初始化并设置正确路径
  6. 在列表操作中添加适当的路径管理,确保对象拥有正确的路径
  7. 修复错误情况下的路径处理,并改进失败日志记录

这些更改确保了在存在重名文件的情况下,文件操作能够正确工作,同时保持数据完整性并防止重复文件在阿里云盘中累积。

…th handling

1. Fix file duplication by implementing a new removeDuplicateFiles method that cleans up duplicate files after operations
2. Change Move operation to use "ignore" for check_name_mode instead of "refuse" to allow moves when destination has same filename
3. Set Copy operation to handle duplicates by removing them after successful copy
4. Improve path handling for all file operations (Move, Rename, Put, MakeDir) by properly maintaining the full path of objects
5. Implement GetRoot interface for proper root object initialization with correct path
6. Add proper path management in List operation to ensure objects have correct paths
7. Fix path handling in error cases and improve logging of failures
@xhofe xhofe requested a review from Copilot April 13, 2025 05:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

drivers/aliyundrive_open/driver.go:244

  • In the Copy function, duplicate removal errors are logged without affecting the overall copy operation. Verify that this behavior is intentional and does not lead to unintended retention of duplicate files.
if err := d.removeDuplicateFiles(ctx, dstDir.GetPath(), srcObj.GetName(), resp.FileID); err != nil {

Comment thread drivers/aliyundrive_open/driver.go Outdated
Comment thread drivers/aliyundrive_open/driver.go Outdated
…icate file removal

Updated the Move, Rename, and Copy methods to log warnings instead of errors when duplicate file removal fails, as the primary operations have already completed successfully. This improves the clarity of logs without affecting the functionality.
@gaoyifan gaoyifan requested a review from Copilot April 13, 2025 07:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

drivers/aliyundrive_open/driver.go:238

  • [nitpick] Changing auto_rename from true to false alters the duplicate file handling behavior. Confirm that this change is intentional and covered by appropriate tests.
"auto_rename":       false,

drivers/aliyundrive_open/driver.go:274

  • [nitpick] Ensure that the object returned from upload implements model.SetPath; otherwise, the file path may remain unset. Consider adding fallback logic or validating the type before setting the path.
if objWithPath, ok := obj.(model.SetPath); ok {

Comment thread drivers/aliyundrive_open/util.go Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@gaoyifan gaoyifan requested a review from Copilot April 13, 2025 07:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (3)

drivers/aliyundrive_open/driver.go:187

  • Ensure that dstDir.GetPath() never returns an empty string; otherwise, joining an empty base may lead to incorrect paths. Consider defaulting to '/' if an empty path is possible.
srcObj.Path = filepath.Join(dstDir.GetPath(), srcObj.GetName())

drivers/aliyundrive_open/driver.go:222

  • [nitpick] Using an empty string and '.' to decide the valid parentPath may lead to inconsistencies. Consider normalizing the parent path with a standard function or defaulting to '/' to ensure reliable path construction.
if parentPath != "" && parentPath != "." {

drivers/aliyundrive_open/driver.go:272

  • When uploading, if dstDir.GetPath() is empty the resulting object may end up with an empty path. Explicitly default to '/' or another valid base directory to avoid this potential issue.
if obj != nil && obj.GetPath() == "" {

@xhofe xhofe merged commit 0a9921f into AlistGo:main Apr 19, 2025
12 checks passed
@gaoyifan gaoyifan mentioned this pull request Apr 21, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants