Skip to content

Conversation

@liyigang1
Copy link
Contributor

Merge v20 and v25 branch codes, merge branches into one

liyigang1 and others added 5 commits December 19, 2025 16:19
- Introduced DLocalHelper::createGFile to centralize GFile creation from QUrl or path, replacing direct g_file_new_for_uri/g_file_new_for_path calls throughout the codebase.
- Updated DFile, DFileInfo, DEnumerator, DOperator, DWatcher, DFMUtils, and related tools to use the new helper for improved consistency and maintainability.
- Added DFMUtils::isUnvalidCodecByPath to check for invalid codec in file paths, and integrated this check in DEnumerator and DLocalHelper to set userInfo in QUrl when necessary.
- Improved symlink handling in DLocalHelper::createSortFileInfo to use fromLocal8Bit for target paths.
- Enhanced robustness and code clarity in file operations and path handling.

Log: Refactor GFile creation and add codec validation for file paths
Bug: https://pms.uniontech.com//bug-view-315953.html
- Introduced OperatorsFileUtils singleton class with delayRemoveCopyingFile method to delay the removal of copying file URLs by 500ms.
- Updated FileOperateBaseWorker to use OperatorsFileUtils::delayRemoveCopyingFile instead of direct FileUtils::removeCopyingFileUrl calls.
- Enhances safety and reliability of file operations by preventing premature removal of file URLs.

Log: add OperatorsFileUtils for delayed removal of copying file URLs
Bug: https://pms.uniontech.com//bug-view-315953.html
- Add symlinkTarget() and resolveSymlink() helpers to resolve symlink chains and detect cycles
- Add fileSizeByEnt() to correctly determine file size for symlinks, including chained symlinks
- Update compareBySize() to use fileSizeByEnt() for accurate sorting
- Refactor createSortFileInfo() to use resolveSymlink() for symlink targets and update file size and isDir accordingly
- Fix stat usage to handle UTF-8 paths and improve symlink resolution logic
- Ensure isDir and isFile are set correctly for symlinks and their targets

These changes improve the accuracy of file size and type detection for symlinks, especially when sorting or displaying file information.

Log: improve symlink handling and file size calculation in DLocalHelper
Bug:
- Add initEnumerator demo mode to showcase different enumeration methods
- Implement better error handling and logging in DEnumerator
- Fix potential memory leaks in filePath and sortFileInfoList functions
- Update dfm-list tool to include demo mode for testing new features

Log: feat(denumerator): add initEnumerator demo and improve error handling
Bug: https://pms.uniontech.com/bug-view-333909.html
…evelop/eagle-20250617 to master

 - Use DLocalHelper::createGFile with proper spacing in dfm-copy3 for code style consistency.
 - Update DLocalHelper::fileSizeByEnt to return -1 for directories, avoiding misuse of directory st_size as a regular file size.
 - Refactor DEnumeratorPrivate::hasNext to build nextUrl via buildUrl, improving robustness and correctness of path construction.

Log: improve path handling and file size detection in dfm-io, merge develop/eagle-20250617 to master
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码进行详细审查:

  1. 代码逻辑和功能改进:
  • 在 DFMUtils 中新增了 isInvalidCodecByPath 函数,用于检查路径编码是否有效。这个实现很好,考虑了 Qt5 和 Qt6 的兼容性。

  • DLocalHelper::createGFile 的实现改进了文件路径处理,能够正确处理带有 originPath:: 前缀的特殊路径。但建议增加对空指针的检查。

  1. 性能优化建议:
  • 在 DEnumeratorPrivate::filePath 函数中,使用了多次字符串操作和内存分配。建议优化路径处理逻辑,减少不必要的字符串复制。

  • buildUrl 函数中的字符串拼接可以优化,使用 QStringBuilder 来提高性能。

  1. 安全性改进:
  • 在 DEnumeratorPrivate::filePath 中使用了 strdup,但没有检查返回值。建议添加空指针检查。

  • 在处理文件路径时,建议增加对路径遍历攻击的防护。

  1. 内存管理:
  • 在 DEnumeratorPrivate::openDirByfts 中,paths[0] 的内存管理需要改进,建议使用智能指针或 RAII 机制。

  • sortFileInfoList 函数中正确释放了 dirPath,这是好的实践。

  1. 代码风格和规范:
  • 一些函数的注释不够完整,建议补充详细的函数说明和参数说明。

  • 建议统一使用 const 引用传递 QString 参数,避免不必要的拷贝。

  1. 具体改进建议:
// 在 DLocalHelper::createGFile 中添加空指针检查
GFile *DLocalHelper::createGFile(const QUrl &uri)
{
    if (!uri.isValid()) {
        qWarning() << "Invalid URI provided";
        return nullptr;
    }

    QString path = uri.userInfo().isEmpty() || !uri.userInfo().startsWith("originPath::") ?
                   QString() : uri.userInfo().replace("originPath::", "");

    return path.isEmpty() ?
           g_file_new_for_uri(uri.toString().toLocal8Bit().data()) :
           g_file_new_for_path(path.toLocal8Bit().data());
}

// 优化 DEnumeratorPrivate::filePath 的内存管理
char *DEnumeratorPrivate::filePath(const QUrl &url)
{
    if (!url.isValid()) {
        qWarning() << "Invalid URL provided";
        return nullptr;
    }

    QString path;
    if (url.userInfo().startsWith("originPath::")) {
        path = url.userInfo().replace("originPath::", "");
    } else {
        path = url.path();
        if (path != "/" && path.endsWith("/"))
            path.chop(1);
    }

    return strdup(path.toUtf8().constData());
}

// 优化 buildUrl 函数的字符串拼接
QUrl DEnumeratorPrivate::buildUrl(const QUrl &url, const char *fileName)
{
    if (!fileName) {
        qWarning() << "Invalid file name provided";
        return QUrl();
    }

    const QString fileNameStr = QString::fromUtf8(fileName);
    QString path = url.path();
    if (path != "/")
        path += QLatin1Char('/');
    path += fileNameStr;

    QUrl nextUrl = QUrl::fromLocalFile(path);

    if (url.userInfo().startsWith("originPath::")) {
        nextUrl.setUserInfo(url.userInfo() % QLatin1Char('/') % fileNameStr);
    } else if (DFMUtils::isInvalidCodecByPath(fileName)) {
        QString orgPath = url.path();
        if (orgPath != "/")
            orgPath += QLatin1Char('/');
        orgPath += fileNameStr;
        nextUrl.setUserInfo(QLatin1String("originPath::") % orgPath);
    }

    return nextUrl;
}
  1. 其他建议:
  • 建议添加更多的单元测试来覆盖新增的编码检查功能。

  • 在处理文件路径时,建议使用更安全的字符串操作函数,避免潜在的缓冲区溢出。

  • 考虑添加更多的错误处理和日志记录,以便于调试和问题追踪。

这些改进可以提高代码的健壮性、性能和可维护性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@Johnson-zs Johnson-zs merged commit 011103b into linuxdeepin:master Dec 22, 2025
19 of 20 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.

5 participants