Skip to content

fix: update libzip archive data in-memory like libarchive - #495

Open
LiHua000 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
LiHua000:agent/pms-bug-bot/71fdfdb9eff6
Open

LiHua000 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
LiHua000:agent/pms-bug-bot/71fdfdb9eff6

Conversation

@LiHua000

@LiHua000 LiHua000 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

fix: update libzip archive data in-memory like libarchive

  1. Root cause: LibzipPlugin::updateArchiveData() ignored the options
    parameter, cleared all memory data, and re-read from disk via
    zip_open() with commented-out error handling on failure
  2. Fix: rewrite updateArchiveData() to use the options parameter for
    in-memory updates (Delete/Rename/Add), mirroring
    LibarchivePlugin::updateArchiveData(), eliminating disk re-read
    fragility and restoring proper error handling
  3. Impact: zip format archives now refresh UI immediately after
    rename/delete/add operations without reopening, consistent with
    tar format behavior; no signature change, single caller via
    virtual dispatch unaffected

Influence:

  1. Test zip archive file rename, verify UI shows new name immediately
  2. Test zip archive file/folder delete, verify UI updates instantly
  3. Test zip archive file add, verify new entry appears without reopen
  4. Test multi-level path folder rename/delete in zip archives
  5. Verify tar format operations remain unaffected

fix: 修复zip格式压缩包重命名后需重新打开才显示的问题

  1. 根因:LibzipPlugin::updateArchiveData() 忽略 options 参数,清空
    全部内存数据后通过 zip_open() 从磁盘重读,且 zip_open 失败时
    错误处理被注释掉,导致内存数据为空或过时,UI 无法正确刷新
  2. 方案:参照 LibarchivePlugin::updateArchiveData() 实现,改用
    options 参数做内存级更新(Delete/Rename/Add),消除磁盘重读
    脆弱性,恢复错误处理
  3. 影响:zip 格式压缩包重命名/删除/追加后 UI 即时刷新,与 tar
    格式行为一致;函数签名不变,单一调用方通过虚函数分派不受影响

Influence:

  1. 测试zip压缩包内文件重命名,验证UI即时显示新名称
  2. 测试zip压缩包内文件/文件夹删除,验证UI即时更新
  3. 测试zip压缩包内文件追加,验证新条目无需重开即可显示
  4. 测试多层路径文件夹的重命名/删除操作
  5. 验证tar格式操作不受影响

PMS: BUG-232441

Summary by Sourcery

Keep ZIP archive views synchronized immediately after internal file operations while preventing redundant file-watcher handling.

Bug Fixes:

  • Update ZIP archive metadata in memory after file and folder additions, deletions, and renames so the UI reflects changes without reopening the archive.

Enhancements:

  • Suppress file-watcher reactions during internal archive operations and consistently restore watcher state after completion, cancellation, errors, or window reset.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LiHua000

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 Sep 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

LibzipPlugin::updateArchiveData() now applies delete, rename, and add operations directly to DataManager’s in-memory archive state instead of clearing it and rereading from disk, enabling immediate UI refresh while preserving the existing dispatch interface and tar behavior.

Sequence diagram for in-memory ZIP archive updates

sequenceDiagram
    participant Operation as ArchiveOperation
    participant Plugin as LibzipPlugin
    participant Data as DataManager
    participant UI as ArchiveUI

    Operation->>Plugin: updateArchiveData(options)
    Plugin->>Data: archiveData()
    alt Delete
        Plugin->>Data: remove entries and update qSize
    else Rename
        Plugin->>Data: replace paths in mapFileEntry and listRootEntry
    else Add
        Plugin->>Data: insert entry and update qSize
    end
    Plugin-->>Operation: PFT_Nomral
    Operation-->>UI: refresh from in-memory archive state
Loading

File-Level Changes

Change Details Files
Replaced disk-based archive reloading with incremental in-memory synchronization driven by the requested update operation.
  • Process Delete, Rename, and Add entries from UpdateOptions.
  • Remove deleted files and directory descendants while maintaining archive size and root entries.
  • Rewrite renamed file and directory paths in the entry map and root listing.
  • Insert added entries at the destination path and update size metadata.
  • Refresh compressed-size metadata without reopening the archive.
3rdparty/libzipplugin/libzipplugin.cpp
Preserved the existing update API while aligning libzip behavior with the libarchive implementation.
  • Begin consuming the existing options parameter without changing the virtual method signature.
  • Eliminate zip_open-based reconstruction and its incomplete failure handling.
  • Keep the operation confined to the libzip plugin, leaving tar handling unchanged.
3rdparty/libzipplugin/libzipplugin.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

@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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="3rdparty/libzipplugin/libzipplugin.cpp" line_range="631-633" />
<code_context>
+                        if (stArchiveData.listRootEntry.at(i).strFullPath == entry.strFullPath) { // 在第一次层数据中找到entry移除
+                            stArchiveData.listRootEntry.removeAt(i);
+                            strAlias = entry.strAlias + QDir::separator();
+                            entry.strFullPath = strAlias;
+                            entry.strFileName = strAlias;
+                            stArchiveData.listRootEntry.append(entry);
+                            break;
+                        }
</code_context>
<issue_to_address>
**issue (bug_risk):** Root-level directory rename stores `strFileName` as the full aliased path including the trailing separator instead of the directory basename, so the root listing displays a path-like name rather than the renamed folder name.

**Triggers:** When renaming a directory at the archive root.

**Suggested fix:** Assign `QFileInfo(strAlias).fileName()` (or the directory basename without the trailing separator) to `entry.strFileName`.
</issue_to_address>

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

Comment on lines +631 to +633
entry.strFullPath = strAlias;
entry.strFileName = strAlias;
stArchiveData.listRootEntry.append(entry);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Root-level directory rename stores strFileName as the full aliased path including the trailing separator instead of the directory basename, so the root listing displays a path-like name rather than the renamed folder name.

Triggers: When renaming a directory at the archive root.

Suggested fix: Assign QFileInfo(strAlias).fileName() (or the directory basename without the trailing separator) to entry.strFileName.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 93 分 (通过阈值: 70分)

Fail


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 未发现严重安全问题,代码逻辑正确,实现了内存级更新替代磁盘重读的改进。存在少量代码质量和性能优化空间。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 良好 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['建议将重复的root entry更新逻辑提取为辅助函数,如:void updateRootEntry(ArchiveData &data, const FileEntry &oldEntry, const FileEntry &newEntry, bool isRename)', '建议将Delete/Rename/Add三个操作分支分别提取为独立函数,提升可读性和可维护性']


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['建议使用 foreach (const FileEntry &entry, options.listEntry) 避免不必要的对象拷贝', '建议将目录前缀计算(strPath和strAlias前半段)移到while循环外部,只计算一次']


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: ['代码采用内存级数据操作替代旧的磁盘读取方式,消除了zip_open()失败时错误处理被注释掉的安全隐患,安全性有所提升']


💡 改进建议代码示例

// 暂无代码示例

本报告由 AI 代码审查工具自动生成

1. Root cause: LibzipPlugin::updateArchiveData() ignored the options
   parameter, cleared all memory data, and re-read from disk via
   zip_open() with commented-out error handling on failure
2. Fix: rewrite updateArchiveData() to use the options parameter for
   in-memory updates (Delete/Rename/Add), mirroring
   LibarchivePlugin::updateArchiveData(), eliminating disk re-read
   fragility and restoring proper error handling
3. Impact: zip format archives now refresh UI immediately after
   rename/delete/add operations without reopening, consistent with
   tar format behavior; no signature change, single caller via
   virtual dispatch unaffected

Influence:
1. Test zip archive file rename, verify UI shows new name immediately
2. Test zip archive file/folder delete, verify UI updates instantly
3. Test zip archive file add, verify new entry appears without reopen
4. Test multi-level path folder rename/delete in zip archives
5. Verify tar format operations remain unaffected

fix: 修复zip格式压缩包重命名后需重新打开才显示的问题

1. 根因:LibzipPlugin::updateArchiveData() 忽略 options 参数,清空
   全部内存数据后通过 zip_open() 从磁盘重读,且 zip_open 失败时
   错误处理被注释掉,导致内存数据为空或过时,UI 无法正确刷新
2. 方案:参照 LibarchivePlugin::updateArchiveData() 实现,改用
   options 参数做内存级更新(Delete/Rename/Add),消除磁盘重读
   脆弱性,恢复错误处理
3. 影响:zip 格式压缩包重命名/删除/追加后 UI 即时刷新,与 tar
   格式行为一致;函数签名不变,单一调用方通过虚函数分派不受影响

Influence:
1. 测试zip压缩包内文件重命名,验证UI即时显示新名称
2. 测试zip压缩包内文件/文件夹删除,验证UI即时更新
3. 测试zip压缩包内文件追加,验证新条目无需重开即可显示
4. 测试多层路径文件夹的重命名/删除操作
5. 验证tar格式操作不受影响

PMS: BUG-232441
@LiHua000
LiHua000 force-pushed the agent/pms-bug-bot/71fdfdb9eff6 branch from 46ca314 to 10718d1 Compare October 8, 2026 01:59
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