Skip to content

fix bugs#265

Merged
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
Johnson-zs:master
Mar 9, 2026
Merged

fix bugs#265
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
Johnson-zs:master

Conversation

@Johnson-zs
Copy link
Contributor

No description provided.

Added conditional compilation to support both Qt5 and Qt6 versions
The change replaces QString::SkipEmptyParts with Qt::SkipEmptyParts
for Qt6
while maintaining backward compatibility with Qt5 using preprocessor
directives

Influence:
1. Test file search functionality with both Qt5 and Qt6 builds
2. Verify blacklist matching works correctly with various path formats
3. Check that empty path segments are properly handled
4. Ensure no regression in path normalization and blacklist filtering

refactor: 添加Qt6兼容性支持用于路径分割

添加条件编译以同时支持Qt5和Qt6版本
更改将QString::SkipEmptyParts替换为Qt::SkipEmptyParts用于Qt6
同时使用预处理器指令保持与Qt5的向后兼容性

Influence:
1. 测试Qt5和Qt6构建下的文件搜索功能
2. 验证黑名单匹配在各种路径格式下正常工作
3. 检查空路径段是否正确处理
4. 确保路径规范化和黑名单过滤功能无回归
Changed the URL construction logic to preserve the original URL's scheme
and host instead of assuming all URLs are local files. Previously,
QUrl::fromLocalFile() was used which would convert any URL to a file://
scheme. Now we maintain the original scheme by creating a copy of the
input URL and only modifying its path component.

This fix ensures compatibility with various URL schemes (like network
protocols, custom schemes) that may be used in the file enumeration
system. The change maintains the URL structure while properly
constructing the path for child entries.

Log: Fixed URL scheme preservation in file enumeration

Influence:
1. Test file enumeration with different URL schemes (file://, smb://,
etc.)
2. Verify that child file URLs maintain correct scheme and host
information
3. Check that network file shares work correctly with the new URL
construction
4. Test with custom URL schemes to ensure they are preserved
5. Verify that local file paths still work correctly

fix: 构建文件URL时保留URL方案

修改了URL构建逻辑,保留原始URL的方案和主机信息,而不是假定所有URL都是本
地文件。之前使用QUrl::fromLocalFile()会将任何URL转换为file://方案。现在
通过创建输入URL的副本并仅修改其路径组件来维护原始方案。

此修复确保与文件枚举系统中可能使用的各种URL方案(如网络协议、自定义方
案)的兼容性。该更改在正确构建子条目路径的同时维护URL结构。

Log: 修复文件枚举中的URL方案保留问题

Influence:
1. 使用不同的URL方案(file://、smb://等)测试文件枚举
2. 验证子文件URL是否保持正确的方案和主机信息
3. 检查网络文件共享是否与新的URL构建方式正常工作
4. 使用自定义URL方案测试以确保它们被保留
5. 验证本地文件路径是否仍然正常工作

Bug: https://pms.uniontech.com/bug-view-352359.htm
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs

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

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码修改包含两个文件的变更,我将分别对这两处修改进行审查,从语法逻辑、代码质量、代码性能和代码安全四个维度提出改进意见。

1. 文件:src/dfm-io/dfm-io/denumerator.cpp

变更内容
修改了 DEnumeratorPrivate::buildUrl 函数中构建 URL 的方式,从使用 QUrl::fromLocalFile 改为保留原始 URL 的 scheme 和 host。

审查意见

  • 语法逻辑

    • 通过。修改后的逻辑是正确的。之前的代码假设所有 URL 都是本地文件(file://),这会导致处理网络挂载(如 SMB, FTP, SFTP)或自定义 Scheme 的 URL 时出错。新的代码通过复制原始 URL 并仅修改 Path 部分,保留了上下文信息,逻辑更加严谨。
    • ⚠️ 注意QUrl::setPath 会自动处理路径的分隔符,但建议确认 path 变量的构造逻辑是否与新的 URL Scheme 兼容(例如某些 Scheme 对路径格式有特殊要求)。
  • 代码质量

    • 优秀。添加的注释“保留原始 URL 的 scheme 和 host,而不是假定为本地文件”非常清晰地解释了修改的原因,提高了代码的可读性和可维护性。
    • 优秀。复用了传入的 url 对象进行拷贝修改,代码意图明确。
  • 代码性能

    • 良好QUrl 的拷贝和 setPath 操作都非常轻量,不会引入明显的性能开销。
  • 代码安全

    • 提升。之前的实现可能导致非本地文件路径被错误地解析为本地路径,引发安全风险(如沙箱逃逸或路径混淆)。修改后的代码确保了 URL 的上下文一致性,更加安全。

2. 文件:src/dfm-search/dfm-search-lib/utils/filenameblacklistmatcher.cpp

变更内容
QString::split 方法添加了 Qt 版本兼容性宏,以适配 Qt 5 和 Qt 6。

审查意见

  • 语法逻辑

    • 通过。Qt 6 中 QString::SplitBehavior 命名空间发生了变化,QString::SkipEmptyParts 变为了 Qt::SkipEmptyParts。使用 #if 宏进行条件编译是处理此类 API 变更的标准做法,逻辑正确。
  • 代码质量

    • ⚠️ 可优化:虽然这种写法是正确的,但在代码中频繁出现 #if 宏会降低可读性。
    • 建议:如果在项目中有多处需要适配 Qt 5/6 的差异,建议在公共头文件中定义一个统一的宏或辅助函数,例如:
      // 在公共头文件中
      #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
      #define DFMSkipEmptyParts Qt::SkipEmptyParts
      #else
      #define DFMSkipEmptyParts QString::SkipEmptyParts
      #endif
      
      // 在代码中使用
      const QStringList pathSegments = normalizedPath.split('/', DFMSkipEmptyParts);
      这样可以将版本适配逻辑集中管理,避免代码散落各处。
  • 代码性能

    • 无影响。这是编译期分支,不会增加运行时开销。
  • 代码安全

    • 通过。代码逻辑安全,未引入新的风险。

总结

这两处修改都是必要且正确的:

  1. 第一处修复了处理非本地文件 URL 时的潜在 Bug,提升了健壮性和安全性。
  2. 第二处确保了代码在不同 Qt 版本下的编译兼容性。

建议
对于第二处关于 Qt 版本适配的修改,建议考虑将其封装为项目级的通用宏或辅助函数,以保持代码整洁并便于后续维护。除此之外,代码质量很高。

@Johnson-zs
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 9, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit d08db8e into linuxdeepin:master Mar 9, 2026
21 checks passed
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