-
Notifications
You must be signed in to change notification settings - Fork 37
Fix: Improve folder name handling in archive path construction #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Improve folder name handling in archive path construction #322
Conversation
-- 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
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis 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 logicclassDiagram
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
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if (compressor.indexOf(reg) != -1) | ||
| compressor.remove(reg); |
There was a problem hiding this comment.
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 pr auto review我来对这个代码变更进行审查:
改进建议: // 添加辅助函数处理文件夹名称
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;
}
}
// ... 其他代码 ...
}这些改进将:
|
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
-- 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: