Skip to content

Fix: Refactor long file name handling in common interface#323

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/snipefrom
GongHeng2017:upstream/develop/snipe
Nov 21, 2025
Merged

Fix: Refactor long file name handling in common interface#323
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/snipefrom
GongHeng2017:upstream/develop/snipe

Conversation

@GongHeng2017
Copy link
Copy Markdown
Contributor

@GongHeng2017 GongHeng2017 commented Nov 20, 2025

-- Renamed functions and updated logic to improve clarity and consistency in handling long file names across the codebase. The function isSubpathOfDlnfs is now isSubpathOfLnfs, and findDlnfsPath has been changed to findLnfsPath. This refactoring enhances the readability of the code and ensures that the correct file system types are checked for long file name support.

Log: Refactor long file name handling in common interface
Bug: https://pms.uniontech.com/bug-view-326015.html

Summary by Sourcery

Refactor long file name handling by renaming related functions to ‘Lnfs’, enhancing detection logic to check fuse.dlnfs and ulnfs filesystem types, improving logging, and updating all plugin callers accordingly

Bug Fixes:

  • Ensure correct file system types are checked for long file name support by validating fuse.dlnfs and ulnfs rather than relying on source string matching

Enhancements:

  • Rename long filename detection functions from Dlnfs to Lnfs (isSubpathOfDlnfs→isSubpathOfLnfs, findDlnfsPath→findLnfsPath) across the common interface and plugins
  • Improve logging in Common::findLnfsPath to output filesystem type and mount point during detection
  • Update UiTools::isLocalDeviceFile to detect local devices by filesystem type in addition to device paths

-- Renamed functions and updated logic to improve clarity and consistency in handling long file names across the codebase. The function `isSubpathOfDlnfs` is now `isSubpathOfLnfs`, and `findDlnfsPath` has been changed to `findLnfsPath`. This refactoring enhances the readability of the code and ensures that the correct file system types are checked for long file name support.

Log: Refactor long file name handling in common interface
Bug: https://pms.uniontech.com/bug-view-326015.html
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

我来分析一下这个diff的修改内容:

  1. 命名更改:
  • 将所有 bDlnfs 改为 bLnfs
  • isSubpathOfDlnfs 改为 isSubpathOfLnfs
  • findDlnfsPath 改为 findLnfsPath
  • m_bDlnfs 改为 m_bLnfs
  1. 主要功能改进:
  • findLnfsPath 函数中增加了对更多长文件名文件系统的支持:
    • 不仅检查 "dlnfs",还增加了对 "fuse.dlnfs" 和 "ulnfs" 的支持
    • 改进了文件系统类型和挂载点的检查逻辑
    • 增加了更详细的调试日志输出
  1. UiTools::isLocalDeviceFile 中:
  • 改进了对本地设备的判断逻辑
  • 增加了对文件系统类型的检查
  • 将原来的简单字符串匹配改为更精确的文件系统类型判断

代码质量改进建议:

  1. 命名规范:
  • 虽然将 bDlnfs 改为 bLnfs 简化了名称,但建议使用更具描述性的名称,如 isLongNameFileSystemSupported
  • 变量名前缀 b 表示布尔值是旧式命名风格,建议去掉
  1. 错误处理:
  • findLnfsPath 中,应该增加对 mnt_fs_get_fstype 返回值的空指针检查
  • 在文件系统类型比较时,应该增加对大小写的处理
  1. 性能优化:
  • 可以考虑缓存文件系统类型检查的结果,避免重复检查
  • 字符串比较可以使用 QString::compare 并指定 Qt::CaseInsensitive 参数
  1. 代码安全:
  • 在处理挂载点路径时,应该增加路径规范化和验证
  • 建议增加对异常情况的处理,如内存分配失败等
  1. 文档改进:
  • 建议为新增的文件系统类型支持添加注释说明
  • isLocalDeviceFile 函数中添加更详细的文档说明
  1. 代码结构:
  • 考虑将文件系统类型检查逻辑抽取为单独的工具函数
  • 可以使用枚举类型来定义支持的文件系统类型,而不是使用硬编码的字符串

这些修改提高了代码的可维护性和扩展性,但还可以进一步优化以提高代码质量和安全性。

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Nov 20, 2025

Reviewer's Guide

This PR systematically renames DLNFS-related identifiers to LNFS and overhauls long-file-name support checks by switching from a hardcoded source match to filesystem-type detection (fuse.dlnfs or ulnfs), while propagating these changes across the common interface, UI tools, and archive plugins.

Sequence diagram for long file name support check in extraction process

sequenceDiagram
    participant Plugin
    participant Common
    Plugin->>Common: isSubpathOfLnfs(strTargetPath)
    Common->>Common: findLnfsPath(target, func)
    Common->>"mnt_table": iterate filesystems
    Common->>Common: Check fsType ("fuse.dlnfs" or "ulnfs")
    Common-->>Plugin: return true/false
    Plugin->>Plugin: Use bLnfs to determine extraction logic
Loading

Class diagram for updated long file name handling in Common interface

classDiagram
    class Common {
        +QString handleLongNameforPath(strFilePath, entryName, mapLongDirName, mapRealDirValue)
        +bool isSubpathOfLnfs(path)
        +bool isSupportSeek(sFileName)
        -bool findLnfsPath(target, func)
    }
Loading

Class diagram for updated long file name support in LibzipPlugin

classDiagram
    class LibzipPlugin {
        QMap<QString, int> m_mapLongDirName
        QMap<QString, int> m_mapRealDirValue
        QSet<QString> m_setLongName
        bool m_bLnfs
    }
Loading

Class diagram for updated long file name support in CliInterface

classDiagram
    class CliInterface {
        +PluginFinishType extractFiles(files, options, bLnfs)
    }
Loading

Class diagram for updated local device file check in UiTools

classDiagram
    class UiTools {
        +bool isLocalDeviceFile(strFileName)
        +QStringList removeSameFileName(listFiles)
    }
Loading

File-Level Changes

Change Details Files
Rename DLNFS identifiers to LNFS
  • Renamed isSubpathOfDlnfs to isSubpathOfLnfs and findDlnfsPath to findLnfsPath
  • Updated method signatures and header declarations accordingly
  • Replaced bDlnfs variables and property names with bLnfs/lnfs
3rdparty/interface/common.cpp
3rdparty/interface/common.h
3rdparty/interface/archiveinterface/cliinterface.cpp
3rdparty/interface/archiveinterface/cliinterface.h
3rdparty/libarchive/libarchive/libarchiveplugin.cpp
3rdparty/libzipplugin/libzipplugin.cpp
3rdparty/libzipplugin/libzipplugin.h
Refactor long-name filesystem detection logic
  • Retrieve fs type and mount point via mnt_fs_get_fstype/target
  • Define isLongFileNameFS for fuse.dlnfs or ulnfs
  • Apply callback when filesystem supports long filenames instead of hardcoded source check
3rdparty/interface/common.cpp
Improve UI device vs. long-name FS detection
  • Use QStorageInfo.fileSystemType for detection
  • Return true for '/dev/' devices or fuse.dlnfs/ulnfs types
src/source/common/uitools.cpp
Propagate LNFS flag in extraction workflows
  • Switch conditional branches and extractFiles calls to use lnfs flag
  • Update property setting and handling in CLI and plugin code
3rdparty/interface/archiveinterface/cliinterface.cpp
3rdparty/libarchive/libarchive/libarchiveplugin.cpp
3rdparty/libzipplugin/libzipplugin.cpp
Enhanced logging for mount checks
  • Added qInfo statements showing filesystem type and mount point during iteration
3rdparty/interface/common.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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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

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

## Individual Comments

### Comment 1
<location> `3rdparty/interface/common.cpp:487` </location>
<code_context>
 }

-bool Common::findDlnfsPath(const QString &target, Compare func)
+bool Common::findLnfsPath(const QString &target, Compare func)
 {
     Q_ASSERT(func);
</code_context>

<issue_to_address>
**issue (complexity):** Consider refactoring the loop to use RAII for resource management, move invariant computations outside the loop, and simplify type comparisons to reduce complexity.

You can dramatically flatten this by

  • pulling `unifyPath(target)` out of the loop  
  • comparing raw `const char*` against a tiny static list (no `QString` temp)  
  • using RAII for your table/iter so you don’t need to sprinkle frees everywhere  
  • removing the per-fs logging (or guard it behind a `DEBUG`-only flag)  

For example:

```cpp
// small RAII wrappers for auto‐freeing
struct MntTable {
    libmnt_table *ptr{ mnt_new_table() };
    ~MntTable() { if (ptr) mnt_free_table(ptr); }
};
struct MntIter {
    libmnt_iter *ptr{ mnt_new_iter(MNT_ITER_BACKWARD) };
    ~MntIter() { if (ptr) mnt_free_iter(ptr); }
};

bool Common::findLnfsPath(const QString &target, Compare func) {
    Q_ASSERT(func);
    MntTable table;
    MntIter iter;
    if (mnt_table_parse_mtab(table.ptr, nullptr) != 0)
        return false;

    const QString targetPath = unifyPath(target);
    static constexpr const char* kLnfsTypes[] = {"fuse.dlnfs", "ulnfs"};

    libmnt_fs *fs = nullptr;
    while (mnt_table_next_fs(table.ptr, iter.ptr, &fs) == 0 && fs) {
        const char* mountPoint = mnt_fs_get_target(fs);
        if (!mountPoint) continue;

        // raw C‐string compare, no QString temp
        for (auto type : kLnfsTypes) {
            if (strcmp(mnt_fs_get_fstype(fs), type) == 0 &&
                func(targetPath, unifyPath(mountPoint))) {
                return true;
            }
        }
    }
    return false;
}
```

This

 1. moves the `unifyPath(target)` call out of the hot loop  
 2. drops all `QString` conversions of `fstype` into raw `strcmp`  
 3. eliminates deep nesting by inverting and combining conditions  
 4. uses RAII (`MntTable`/`MntIter`) so you never forget a free—or need to null-check before freeing.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

}

bool Common::findDlnfsPath(const QString &target, Compare func)
bool Common::findLnfsPath(const QString &target, Compare func)
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 (complexity): Consider refactoring the loop to use RAII for resource management, move invariant computations outside the loop, and simplify type comparisons to reduce complexity.

You can dramatically flatten this by

• pulling unifyPath(target) out of the loop
• comparing raw const char* against a tiny static list (no QString temp)
• using RAII for your table/iter so you don’t need to sprinkle frees everywhere
• removing the per-fs logging (or guard it behind a DEBUG-only flag)

For example:

// small RAII wrappers for auto‐freeing
struct MntTable {
    libmnt_table *ptr{ mnt_new_table() };
    ~MntTable() { if (ptr) mnt_free_table(ptr); }
};
struct MntIter {
    libmnt_iter *ptr{ mnt_new_iter(MNT_ITER_BACKWARD) };
    ~MntIter() { if (ptr) mnt_free_iter(ptr); }
};

bool Common::findLnfsPath(const QString &target, Compare func) {
    Q_ASSERT(func);
    MntTable table;
    MntIter iter;
    if (mnt_table_parse_mtab(table.ptr, nullptr) != 0)
        return false;

    const QString targetPath = unifyPath(target);
    static constexpr const char* kLnfsTypes[] = {"fuse.dlnfs", "ulnfs"};

    libmnt_fs *fs = nullptr;
    while (mnt_table_next_fs(table.ptr, iter.ptr, &fs) == 0 && fs) {
        const char* mountPoint = mnt_fs_get_target(fs);
        if (!mountPoint) continue;

        // raw C‐string compare, no QString temp
        for (auto type : kLnfsTypes) {
            if (strcmp(mnt_fs_get_fstype(fs), type) == 0 &&
                func(targetPath, unifyPath(mountPoint))) {
                return true;
            }
        }
    }
    return false;
}

This

  1. moves the unifyPath(target) call out of the hot loop
  2. drops all QString conversions of fstype into raw strcmp
  3. eliminates deep nesting by inverting and combining conditions
  4. uses RAII (MntTable/MntIter) so you never forget a free—or need to null-check before freeing.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017, lzwind

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

@GongHeng2017
Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot deepin-bot bot merged commit 350b81d into linuxdeepin:develop/snipe Nov 21, 2025
15 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.

3 participants