-
Notifications
You must be signed in to change notification settings - Fork 37
Fix: [zipplugin] Show password error. #309
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: [zipplugin] Show password error. #309
Conversation
-- When enter the right password, show password error. -- Not judge the Second password, so add code logic the adjust it. Log: fix issue Bug: https://pms.uniontech.com/bug-view-329305.html
deepin pr auto review我对这段代码进行审查,提供以下改进建议:
// 在类中定义最大密码尝试次数
static const int MAX_PASSWORD_ATTEMPTS = 3;
// 提取密码验证逻辑为单独函数
bool LibzipPlugin::handlePasswordError(zip_int64_t currentIndex, int& attemptCount) {
if (m_eErrorType != ET_WrongPassword && m_eErrorType != ET_NeedPassword) {
return false;
}
// 检查尝试次数
if (++attemptCount >= MAX_PASSWORD_ATTEMPTS) {
zip_close(archive);
m_strPassword = "";
return false;
}
// 如果是重复尝试同一文件且密码错误,直接返回
if (attemptCount > 1 && lastNeedPasswordIndex == currentIndex) {
zip_close(archive);
m_strPassword = "";
return false;
}
PasswordNeededQuery query(strFileName);
emit signalQuery(&query);
query.waitForResponse();
if (query.isAccepted()) {
setPassword(query.password());
zip_set_default_password(archive, m_strPassword.toUtf8().constData());
lastNeedPasswordIndex = currentIndex;
return true;
}
return false;
}
// 在extractFiles函数中使用
for (zip_int64_t i = 0; i < nofEntries; ++i) {
if (QThread::currentThread()->isInterruptionRequested()) {
// ... 现有代码 ...
}
int passwordAttempts = 0;
while (true) {
// ... 现有解压逻辑 ...
if (error) {
if (!handlePasswordError(i, passwordAttempts)) {
return PFT_Error;
}
continue; // 密码正确后重试当前文件
}
break;
}
}
这些改进建议旨在提高代码的可维护性、安全性和性能,同时保持原有功能不变。根据实际需求,可以选择实施部分或全部建议。 |
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.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideIn extractFiles, this PR refactors the password prompt flow to track and handle consecutive wrong-password attempts for the same archive entry, preventing false error signals when a correct password is supplied. Sequence diagram for improved password error handling in extractFilessequenceDiagram
participant Plugin as LibzipPlugin
participant Archive as zip archive
participant User as actor User
participant Query as PasswordNeededQuery
Plugin->>Archive: Attempt to extract entry[i]
alt Password required or wrong password
Plugin->>Query: Emit signalQuery for password
User->>Query: Enter password
Query->>Plugin: Return password
Plugin->>Archive: Set password and retry
alt Password still wrong for same entry
Plugin->>Archive: Close archive
Plugin->>User: Show password error
else Password correct
Plugin->>Archive: Continue extraction
end
else No password needed
Plugin->>Archive: Continue extraction
end
Class diagram for updated LibzipPlugin password handlingclassDiagram
class LibzipPlugin {
+extractFiles(files, options)
-m_eErrorType
-m_strPassword
-lastNeedPasswordIndex
}
class PasswordNeededQuery {
+password()
+waitForResponse()
}
LibzipPlugin "1" -- "*" PasswordNeededQuery: emits signalQuery
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017, liyigang1, max-lvs 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 |
-- When enter the right password, show password error. -- Not judge the Second password, so add code logic the adjust it.
Log: fix issue
Bug: https://pms.uniontech.com/bug-view-329305.html
Summary by Sourcery
Fix password error handling in libzip plugin to properly track and limit password retries
Bug Fixes:
Enhancements: