Skip to content

fix: resolve empty directory migration failure - #846

Draft
pppanghu77 wants to merge 1 commit into
linuxdeepin:release/v20from
pppanghu77:agent/agent/d9302bc955fc
Draft

pppanghu77 wants to merge 1 commit into
linuxdeepin:release/v20from
pppanghu77:agent/agent/d9302bc955fc

Conversation

@pppanghu77

@pppanghu77 pppanghu77 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

fix: resolve empty directory migration failure

  1. Root cause: getTransferJson() only added top-level user-selected
    items to user_file array, never recursively enumerating empty
    subdirectories; setFile() path truncation from commit a05c2ff
    further broke deep directory source path construction
  2. Fix: recursively enumerate empty subdirectories in
    getTransferJson() and add them to user_file array; remove path
    depth truncation in setFile() and restore correct source path
  3. Impact: empty directories at any depth now migrate correctly;
    no behavior change for files and non-empty directories

Log: fix empty directory migration failure during backup import

Influence:

  1. Test backup and restore with empty directories at various depths
  2. Verify files and non-empty directories still migrate correctly
  3. Test cross-device migration with empty directories

fix: 修复数据迁移时空目录无法迁移的问题

  1. 根因:getTransferJson() 仅将用户选中的顶层项加入 user_file
    数组,未递归枚举空子目录;setFile() 中 a05c2ff 引入的路径
    截断逻辑进一步破坏了深层目录的源路径构造
  2. 方案:在 getTransferJson() 中递归枚举空子目录并加入 user_file
    数组;移除 setFile() 中的路径深度截断逻辑,恢复正确的源路径构造
  3. 影响:任意深度的空目录现在都能正确迁移;对文件和非空目录无行为变化

Log: 修复备份导入时空目录无法迁移的问题

Influence:

  1. 测试不同深度空目录的备份与恢复
  2. 验证文件和非空目录仍能正常迁移
  3. 测试跨设备迁移场景下的空目录处理

PMS: BUG-357381

Summary by Sourcery

Restore empty directories correctly during data migration without changing handling for files or non-empty directories.

Bug Fixes:

  • Fix migration and backup restoration of empty directories at arbitrary nesting depths.
  • Preserve complete source paths so deeply nested files and directories are restored to the correct locations.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pppanghu77

The full list of commands accepted by this bot can be found 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

@sourcery-ai

sourcery-ai Bot commented Oct 29, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR fixes empty-directory migration by adding recursively discovered empty subdirectories to the transfer manifest and removing restore-time path truncation, allowing directories at any depth to migrate while preserving existing file and non-empty-directory behavior.

Sequence diagram for empty-directory migration

sequenceDiagram
    participant TransferHelper
    participant QDirIterator
    participant Manifest
    participant SettingHelper
    participant Destination

    TransferHelper->>QDirIterator: QDirIterator(absPath, Subdirectories)
    loop each subdirectory
        QDirIterator-->>TransferHelper: next()
        TransferHelper->>TransferHelper: entryInfoList(AllEntries)
        alt empty subdirectory
            TransferHelper->>Manifest: append(relPath)
        end
    end
    SettingHelper->>Manifest: read user_file
    loop each manifest path
        SettingHelper->>Destination: setFile(path, filepath)
        SettingHelper->>Destination: create directory at full source path
    end
Loading

File-Level Changes

Change Details Files
Recursively include empty subdirectories in the transfer manifest so backup/import can recreate them at arbitrary nesting depths.
  • Traverse selected directories with QDirIterator.
  • Detect directories with no entries and append normalized home-relative paths to user_file.
  • Avoid duplicate manifest entries.
src/plugins/data-transfer/core/utils/transferhepler.cpp
Preserve complete manifest paths when restoring files and directories instead of truncating them by depth.
  • Remove the two-level path filtering from setFile().
  • Construct the source path using the full manifest-relative path while retaining the target path under the home directory.
src/plugins/data-transfer/core/utils/settinghepler.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@pppanghu77
pppanghu77 marked this pull request as draft October 29, 2026 20:27

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

1. Root cause: getTransferJson() only added top-level user-selected
   items to user_file array, never recursively enumerating empty
   subdirectories; setFile() source path construction using
   filename.mid(filename.indexOf('/')) dropped the first path segment
   for multi-level paths and lacked a separator for top-level paths
2. Fix: recursively enumerate empty subdirectories in
   getTransferJson() and add them to user_file array; use
   filepath + "/" + filename for correct source path construction
3. Impact: empty directories at any depth now migrate correctly;
   no behavior change for files and non-empty directories

Log: fix empty directory migration failure during backup import

Influence:
1. Test backup and restore with empty directories at various depths
2. Verify files and non-empty directories still migrate correctly
3. Test cross-device migration with empty directories

fix: 修复数据迁移时空目录无法迁移的问题

1. 根因:getTransferJson() 仅将用户选中的顶层项加入 user_file
   数组,未递归枚举空子目录;setFile() 中源路径构造使用
   filename.mid(filename.indexOf('/')) 对多级路径丢弃首段、
   对顶层路径缺少分隔符,导致源路径错误
2. 方案:在 getTransferJson() 中递归枚举空子目录并加入 user_file
   数组;使用 filepath + "/" + filename 构造正确的源路径
3. 影响:任意深度的空目录现在都能正确迁移;对文件和非空目录
   无行为变化

Log: 修复备份导入时空目录无法迁移的问题

Influence:
1. 测试不同深度空目录的备份与恢复
2. 验证文件和非空目录仍能正常迁移
3. 测试跨设备迁移场景下的空目录处理

Bug: https://pms.uniontech.com/bug-view-357381.html
PMS: BUG-357381
@pppanghu77
pppanghu77 force-pushed the agent/agent/d9302bc955fc branch from 11725fa to 86ce8aa Compare October 29, 2026 21:50
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.

2 participants