Skip to content

Conversation

@GongHeng2017
Copy link

@GongHeng2017 GongHeng2017 commented Nov 20, 2025

-- Updated the logic for constructing the archive path to handle long folder names, ensuring they do not exceed system limits. This includes trimming folder names when necessary and improving the overall robustness of the path handling.

Log: Improve folder name handling in archive path construction
Bug: https://pms.uniontech.com/bug-view-326399.html

Summary by Sourcery

Bug Fixes:

  • Trim folder names plus suffix to not exceed FILE_TRUNCATION_LENGTH before appending in both compressor and default archive path cases

-- Updated the logic for constructing the archive path to handle long folder names, ensuring they do not exceed system limits. This includes trimming folder names when necessary and improving the overall robustness of the path handling.

Log: Improve folder name handling in archive path construction
Bug: https://pms.uniontech.com/bug-view-326399.html
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 20, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR enhances archive path construction by extracting folder names into variables and enforcing a maximum length (FILE_TRUNCATION_LENGTH) through truncation before appending suffixes, applied consistently in both compressor and default branches.

Class diagram for updated archive path construction logic

classDiagram
    class MainWindow {
        +handleArguments_RightMenu(listParam: QStringList): bool
        -strArchivePath: QString
        -strSuffix: QString
        -FILE_TRUNCATION_LENGTH: int
        -handleArguments_RightMenu() updated logic:
        - Extract folderName from path
        - If folderName.length + strSuffix.length > FILE_TRUNCATION_LENGTH, truncate folderName
        - Construct archive path with truncated folderName and suffix
    }
Loading

File-Level Changes

Change Details Files
Implement folder name truncation to respect system path length limits
  • Extract folder name into a variable before appending suffix
  • Check combined length against FILE_TRUNCATION_LENGTH and truncate if needed
  • Apply truncation logic in both compressor and default branches
src/source/mainwindow.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

@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 - here's some feedback:

  • The folder name truncation logic is duplicated in both branches—consider extracting it into a helper function to reduce code repetition.
  • Make sure FILE_TRUNCATION_LENGTH is based on the filesystem’s byte-length limits rather than QString character count to avoid encoding issues on different platforms.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The folder name truncation logic is duplicated in both branches—consider extracting it into a helper function to reduce code repetition.
- Make sure FILE_TRUNCATION_LENGTH is based on the filesystem’s byte-length limits rather than QString character count to avoid encoding issues on different platforms.

## Individual Comments

### Comment 1
<location> `src/source/mainwindow.cpp:2683-2684` </location>
<code_context>
+                    folderName = folderName.left(FILE_TRUNCATION_LENGTH - strSuffix.length());
+                }
+                QString compressor = folderName + strSuffix;
                 if (compressor.indexOf(reg) != -1)
                     compressor.remove(reg);
                 strArchivePath += QDir::separator() + compressor;
             } else {
</code_context>

<issue_to_address>
**issue:** Removing invalid characters after truncation may still leave an empty compressor name.

If all truncated characters are invalid, compressor may be empty. Please add a check to prevent creating an invalid archive path.
</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.

Comment on lines 2683 to 2684
if (compressor.indexOf(reg) != -1)
compressor.remove(reg);
Copy link

Choose a reason for hiding this comment

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

issue: Removing invalid characters after truncation may still leave an empty compressor name.

If all truncated characters are invalid, compressor may be empty. Please add a check to prevent creating an invalid archive path.

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个代码变更进行审查:

  1. 语法逻辑:
  • 代码逻辑基本正确,但在处理文件夹名称时存在一个潜在问题。在第二个分支中,使用 strpath.mid(iIndex + 1) 去掉分隔符,但应该验证 iIndex + 1 是否在字符串范围内,否则可能导致越界。
  1. 代码质量:
  • 代码重复:两个分支中都有处理长文件夹名称的逻辑,可以提取为一个公共函数来减少代码重复。
  • 命名:compressor 这个变量名不够清晰,建议改为 archiveName 更合适。
  • 注释:虽然添加了注释,但可以更详细地说明为什么需要处理长文件夹名称,以及 FILE_TRUNCATION_LENGTH 的具体含义。
  1. 代码性能:
  • 使用了多次字符串操作(split、mid、indexOf等),在处理大量文件时可能影响性能。建议优化字符串操作。
  1. 代码安全:
  • 文件名长度处理是一个好的改进,可以避免系统限制导致的问题。
  • 但还需要考虑:
    • 文件名中的特殊字符处理是否完整
    • 是否需要处理 Unicode 字符
    • 是否需要考虑不同操作系统的文件名限制差异

改进建议:

// 添加辅助函数处理文件夹名称
QString MainWindow::processFolderName(const QString& folderName, const QString& suffix) {
    QString processedName = folderName;
    // 处理长文件夹名称
    if (processedName.length() + suffix.length() > FILE_TRUNCATION_LENGTH) {
        processedName = processedName.left(FILE_TRUNCATION_LENGTH - suffix.length());
    }
    return processedName;
}

bool MainWindow::handleArguments_RightMenu(const QStringList &listParam)
{
    // ... 其他代码 ...
    REG_EXP reg("^\s+|[\\:*\"'?<>|\r\n\t]");
    if (strpath.mid(iIndex).indexOf(reg) != -1) {
        QString folderName = strpath.split("=").last();
        folderName = processFolderName(folderName, strSuffix);
        if (folderName.indexOf(reg) != -1)
            folderName.remove(reg);
        strArchivePath += QDir::separator() + folderName;
    } else {
        // 添加边界检查
        if (iIndex + 1 < strpath.length()) {
            QString folderName = strpath.mid(iIndex + 1);
            folderName = processFolderName(folderName, strSuffix);
            strArchivePath += QDir::separator() + folderName + strSuffix;
        }
    }
    // ... 其他代码 ...
}

这些改进将:

  1. 提高代码的可维护性
  2. 减少代码重复
  3. 增加安全性(添加边界检查)
  4. 提高代码的可读性
  5. 使代码更容易测试

@deepin-ci-robot
Copy link

[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
Author

/merge

@deepin-bot deepin-bot bot merged commit 6fa837f 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