-
Notifications
You must be signed in to change notification settings - Fork 37
Fix: [smb] Compressed file seek detection #317
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |||||
| #include <QUrl> | ||||||
| #include <QScopedPointer> | ||||||
| #include <QTemporaryDir> | ||||||
| #include <QTimer> | ||||||
|
|
||||||
| #include "common.h" | ||||||
| #include <linux/limits.h> | ||||||
|
|
@@ -73,6 +74,16 @@ PluginFinishType CliInterface::list() | |||||
|
|
||||||
| m_workStatus = WT_List; | ||||||
|
|
||||||
| // 是否支持seek | ||||||
| if(!m_common->isSupportSeek(m_strArchiveName)) { | ||||||
| QTimer::singleShot(1000, this, [=]() { | ||||||
| m_eErrorType = ET_FileSeekError; | ||||||
| emit signalprogress(100); | ||||||
| emit signalFinished(PFT_Error); | ||||||
| }); | ||||||
| return PFT_Error; | ||||||
| } | ||||||
|
|
||||||
| bool ret = false; | ||||||
|
|
||||||
| ret = runProcess(m_cliProps->property("listProgram").toString(), m_cliProps->listArgs(m_strArchiveName, DataManager::get_instance().archiveData().strPassword)); | ||||||
|
|
@@ -89,6 +100,16 @@ PluginFinishType CliInterface::testArchive() | |||||
|
|
||||||
| PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const ExtractionOptions &options) | ||||||
| { | ||||||
| // 是否支持seek | ||||||
| if(!m_common->isSupportSeek(m_strArchiveName)) { | ||||||
| QTimer::singleShot(1000, this, [=]() { | ||||||
| m_eErrorType = ET_FileSeekError; | ||||||
| emit signalprogress(100); | ||||||
| emit signalFinished(PFT_Error); | ||||||
| }); | ||||||
| return PFT_Nomral; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (typo): Typo in return value: 'PFT_Nomral' should be 'PFT_Normal'. Please update the return value to 'PFT_Normal' to ensure correctness.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| bool bDlnfs = m_common->isSubpathOfDlnfs(options.strTargetPath); | ||||||
| setProperty("dlnfs", bDlnfs); | ||||||
| ArchiveData arcData = DataManager::get_instance().archiveData(); | ||||||
|
|
@@ -302,6 +323,16 @@ bool CliInterface::doKill() | |||||
|
|
||||||
| PluginFinishType CliInterface::addFiles(const QList<FileEntry> &files, const CompressOptions &options) | ||||||
| { | ||||||
| // 是否支持seek | ||||||
| if (!files.isEmpty() && !m_common->isSupportSeek(m_strArchiveName)) { | ||||||
| QTimer::singleShot(1000, this, [=]() { | ||||||
| m_eErrorType = ET_FileSeekError; | ||||||
| emit signalprogress(100); | ||||||
| emit signalFinished(PFT_Error); | ||||||
| }); | ||||||
| return PFT_Nomral; | ||||||
| } | ||||||
|
|
||||||
| setPassword(QString()); | ||||||
| m_workStatus = WT_Add; | ||||||
| m_files = files; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| #include <QDebug> | ||
| #include <QFileInfo> | ||
| #include <QDir> | ||
| #include <QTemporaryFile> | ||
|
|
||
| #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) | ||
| #include <QRegularExpression> | ||
|
|
@@ -445,6 +446,44 @@ bool Common::isSubpathOfDlnfs(const QString &path) | |
| }); | ||
| } | ||
|
|
||
| bool Common::isSupportSeek(QString sFileName) | ||
| { | ||
| QFileInfo info(sFileName); | ||
| if(info.exists()) { | ||
| QFile file(sFileName); | ||
| if(file.open(QIODevice::ReadOnly)) { | ||
| if (file.seek(0)) { | ||
| file.close(); | ||
| return true; // 支持 seek | ||
| } | ||
| } | ||
| file.close(); | ||
| } else { | ||
| // 指定临时文件的目录 | ||
| QString tempDir = info.absoluteDir().path(); // 替换为你的目录路径 | ||
| QString fileTemplate = tempDir + "/tempfile_XXXXXX"; // 文件名模板 | ||
| // 创建 QTemporaryFile | ||
| QTemporaryFile tempFile(fileTemplate); | ||
| tempFile.setAutoRemove(true); | ||
| // 尝试打开临时文件 | ||
| if (tempFile.open()) { | ||
| tempFile.write("test\n"); | ||
| tempFile.flush(); | ||
| } | ||
| tempFile.close(); | ||
| QString sFileName = tempFile.fileName(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: Variable shadowing of sFileName may cause confusion. Consider renaming the inner 'sFileName' variable to avoid shadowing the function parameter and improve code clarity. |
||
| QFile file(sFileName); | ||
| if(file.open(QIODevice::ReadOnly)) { | ||
| if (file.seek(0)) { | ||
| file.close(); | ||
| return true; // 支持 seek | ||
| } | ||
| } | ||
| file.close(); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| bool Common::findDlnfsPath(const QString &target, Compare func) | ||
| { | ||
| Q_ASSERT(func); | ||
|
|
||
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 (complexity): Consider refactoring the repeated QTimer error-handling code into a helper function and macro to reduce duplication.
Here’s one way to collapse those three identical QTimer blocks into a single helper + guard macro. This preserves your exact return-values but only writes the “error timer” code once.
Then your three methods collapse to:
That removes three copies of the QTimer+lambda while keeping every return‐value exactly as before.