Skip to content

Commit fc66b9e

Browse files
GongHeng2017deepin-bot[bot]
authored andcommitted
Fix: [smb] Compressed file seek detection
-- Compressed file seek detection Log: fix issue Bug: Bug: https://pms.uniontech.com/bug-view-278613.html
1 parent c626e3d commit fc66b9e

8 files changed

Lines changed: 118 additions & 0 deletions

File tree

3rdparty/interface/archiveinterface/cliinterface.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <QUrl>
4040
#include <QScopedPointer>
4141
#include <QTemporaryDir>
42+
#include <QTimer>
4243

4344
#include "common.h"
4445
#include <linux/limits.h>
@@ -73,6 +74,16 @@ PluginFinishType CliInterface::list()
7374

7475
m_workStatus = WT_List;
7576

77+
// 是否支持seek
78+
if(!m_common->isSupportSeek(m_strArchiveName)) {
79+
QTimer::singleShot(1000, this, [=]() {
80+
m_eErrorType = ET_FileSeekError;
81+
emit signalprogress(100);
82+
emit signalFinished(PFT_Error);
83+
});
84+
return PFT_Error;
85+
}
86+
7687
bool ret = false;
7788

7889
ret = runProcess(m_cliProps->property("listProgram").toString(), m_cliProps->listArgs(m_strArchiveName, DataManager::get_instance().archiveData().strPassword));
@@ -89,6 +100,16 @@ PluginFinishType CliInterface::testArchive()
89100

90101
PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const ExtractionOptions &options)
91102
{
103+
// 是否支持seek
104+
if(!m_common->isSupportSeek(m_strArchiveName)) {
105+
QTimer::singleShot(1000, this, [=]() {
106+
m_eErrorType = ET_FileSeekError;
107+
emit signalprogress(100);
108+
emit signalFinished(PFT_Error);
109+
});
110+
return PFT_Nomral;
111+
}
112+
92113
bool bDlnfs = m_common->isSubpathOfDlnfs(options.strTargetPath);
93114
setProperty("dlnfs", bDlnfs);
94115
ArchiveData arcData = DataManager::get_instance().archiveData();
@@ -302,6 +323,16 @@ bool CliInterface::doKill()
302323

303324
PluginFinishType CliInterface::addFiles(const QList<FileEntry> &files, const CompressOptions &options)
304325
{
326+
// 是否支持seek
327+
if (!files.isEmpty() && !m_common->isSupportSeek(m_strArchiveName)) {
328+
QTimer::singleShot(1000, this, [=]() {
329+
m_eErrorType = ET_FileSeekError;
330+
emit signalprogress(100);
331+
emit signalFinished(PFT_Error);
332+
});
333+
return PFT_Nomral;
334+
}
335+
305336
setPassword(QString());
306337
m_workStatus = WT_Add;
307338
m_files = files;

3rdparty/interface/common.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <QDebug>
1414
#include <QFileInfo>
1515
#include <QDir>
16+
#include <QTemporaryFile>
1617

1718
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1819
#include <QRegularExpression>
@@ -445,6 +446,44 @@ bool Common::isSubpathOfDlnfs(const QString &path)
445446
});
446447
}
447448

449+
bool Common::isSupportSeek(QString sFileName)
450+
{
451+
QFileInfo info(sFileName);
452+
if(info.exists()) {
453+
QFile file(sFileName);
454+
if(file.open(QIODevice::ReadOnly)) {
455+
if (file.seek(0)) {
456+
file.close();
457+
return true; // 支持 seek
458+
}
459+
}
460+
file.close();
461+
} else {
462+
// 指定临时文件的目录
463+
QString tempDir = info.absoluteDir().path(); // 替换为你的目录路径
464+
QString fileTemplate = tempDir + "/tempfile_XXXXXX"; // 文件名模板
465+
// 创建 QTemporaryFile
466+
QTemporaryFile tempFile(fileTemplate);
467+
tempFile.setAutoRemove(true);
468+
// 尝试打开临时文件
469+
if (tempFile.open()) {
470+
tempFile.write("test\n");
471+
tempFile.flush();
472+
}
473+
tempFile.close();
474+
QString sFileName = tempFile.fileName();
475+
QFile file(sFileName);
476+
if(file.open(QIODevice::ReadOnly)) {
477+
if (file.seek(0)) {
478+
file.close();
479+
return true; // 支持 seek
480+
}
481+
}
482+
file.close();
483+
}
484+
return false;
485+
}
486+
448487
bool Common::findDlnfsPath(const QString &target, Compare func)
449488
{
450489
Q_ASSERT(func);

3rdparty/interface/common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class Common: public QObject
4242
QString handleLongNameforPath(const QString &strFilePath, const QString &entryName, QMap<QString, int> &mapLongDirName, QMap<QString, int> &mapRealDirValue);
4343
//当前文件系统是否支持长文件
4444
bool isSubpathOfDlnfs(const QString &path);
45+
/**
46+
* @brief isSupportSeek 是否支持seek操作
47+
* @param sFileName 文件名
48+
*/
49+
bool isSupportSeek(QString sFileName);
4550
private:
4651
//通过mount对应方法判断文件系统是否支持长文件
4752
bool findDlnfsPath(const QString &target, Compare func);

3rdparty/interface/commonstruct.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum ErrorType {
3939

4040
ET_UserCancelOpertion, // 用户取消操作
4141
ET_ExistVolume, // 分卷已存在
42+
ET_FileSeekError // 文件不支持seek
4243
};
4344

4445
//加密类型

3rdparty/libarchive/libarchive/libarchiveplugin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ PluginFinishType LibarchivePlugin::list()
6969
QString fileName = fInfo.fileName();
7070
//因为tar.bz2、tar.lzma、tar.Z直接list时间较长,所以先用7z解压再list处理
7171
if (fileName.endsWith(".tar.bz2") || fileName.endsWith(".tar.lzma") || fileName.endsWith(".tar.Z")) {
72+
// 是否支持seek
73+
if (!m_common->isSupportSeek(m_strArchiveName)) {
74+
m_eErrorType = ET_FileSeekError;
75+
return PFT_Error;
76+
}
7277
// 设置解压临时路径
7378
QString strProcessID = QString::number(QCoreApplication::applicationPid()); // 获取应用进程号
7479
QString tempFilePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation)

3rdparty/libzipplugin/libzipplugin.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ PluginFinishType LibzipPlugin::list()
8383
int errcode = 0;
8484
zip_error_t err;
8585

86+
// 是否支持seek
87+
if (!m_common->isSupportSeek(m_strArchiveName)) {
88+
m_eErrorType = ET_FileSeekError;
89+
return PFT_Error;
90+
}
91+
8692
// 打开压缩包文件
8793
zip_t *archive = zip_open(QFile::encodeName(m_strArchiveName).constData(), ZIP_RDONLY, &errcode); // 打开压缩包文件
8894
zip_error_init_with_code(&err, errcode);
@@ -136,6 +142,12 @@ PluginFinishType LibzipPlugin::extractFiles(const QList<FileEntry> &files, const
136142
// m_bHandleCurEntry = false; //false:提取使用选中文件及子文件 true:提取使用选中文件
137143
zip_error_t err;
138144

145+
// 是否支持seek
146+
if (!m_common->isSupportSeek(m_strArchiveName)) {
147+
m_eErrorType = ET_FileSeekError;
148+
return PFT_Error;
149+
}
150+
139151
// 打开压缩包
140152
zip_t *archive = zip_open(QFile::encodeName(m_strArchiveName).constData(), ZIP_RDONLY, &errcode);
141153
zip_error_init_with_code(&err, errcode);

src/source/common/uistruct.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ enum ErrorInfo {
181181
EI_InsufficientDiskSpace, // 磁盘空间不足
182182
EI_ArchiveNoData, // 压缩包无数据
183183
EI_ExistVolume, // 分卷已存在
184+
EI_FileSeekError // seek失败
184185
};
185186

186187
// 启动应用的方式

src/source/mainwindow.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,10 @@ void MainWindow::handleJobErrorFinished(ArchiveJob::JobType eJobType, ErrorType
18081808
case ET_ExistVolume:
18091809
showErrorMessage(FI_Compress, EI_ExistVolume, true);
18101810
break;
1811+
// ftp目录不支持seek操作
1812+
case ET_FileSeekError:
1813+
showErrorMessage(FI_Compress, EI_FileSeekError, true);
1814+
break;
18111815
default: {
18121816
showErrorMessage(FI_Compress, EI_CreatArchiveFailed, true);
18131817
break;
@@ -1863,6 +1867,10 @@ void MainWindow::handleJobErrorFinished(ArchiveJob::JobType eJobType, ErrorType
18631867
case ET_WrongPassword:
18641868
showErrorMessage(FI_Load, EI_WrongPassword);
18651869
break;
1870+
// ftp目录不支持seek操作
1871+
case ET_FileSeekError:
1872+
showErrorMessage(FI_Load, EI_FileSeekError);
1873+
break;
18661874
default:
18671875
showErrorMessage(FI_Load, EI_ArchiveDamaged);
18681876
break;
@@ -1949,6 +1957,10 @@ void MainWindow::handleJobErrorFinished(ArchiveJob::JobType eJobType, ErrorType
19491957
!(StartupType::ST_ExtractHere == m_eStartupType || StartupType::ST_Extractto == m_eStartupType));
19501958
break;
19511959
}
1960+
// ftp目录不支持seek操作
1961+
case ET_FileSeekError:
1962+
showErrorMessage(FI_Uncompress, EI_FileSeekError);
1963+
break;
19521964
case ET_PluginError: {
19531965
// 无可用插件
19541966
showErrorMessage(FI_Uncompress, EI_NoPlugin);
@@ -2317,6 +2329,10 @@ void MainWindow::showErrorMessage(FailureInfo fFailureInfo, ErrorInfo eErrorInfo
23172329
m_pFailurePage->setFailureDetail(tr("The compressed volumes already exist"));
23182330
}
23192331
break;
2332+
case EI_FileSeekError: {
2333+
m_pFailurePage->setFailureDetail(tr("No compression support in current directory. Download the files to a local device."));
2334+
}
2335+
break;
23202336
default:
23212337
break;
23222338
}
@@ -2343,6 +2359,10 @@ void MainWindow::showErrorMessage(FailureInfo fFailureInfo, ErrorInfo eErrorInfo
23432359
m_pFailurePage->setFailureDetail(tr("Some volumes are missing"));
23442360
}
23452361
break;
2362+
case EI_FileSeekError: {
2363+
m_pFailurePage->setFailureDetail(tr("Can't open compressed packages in current directory. Download the compressed package to a local device."));
2364+
}
2365+
break;
23462366
default:
23472367
break;
23482368
}
@@ -2384,6 +2404,10 @@ void MainWindow::showErrorMessage(FailureInfo fFailureInfo, ErrorInfo eErrorInfo
23842404
m_pFailurePage->setFailureDetail(tr("Insufficient disk space"));
23852405
}
23862406
break;
2407+
case EI_FileSeekError: {
2408+
m_pFailurePage->setFailureDetail(tr("No extraction support in current directory. Download the compressed package to a local device."));
2409+
}
2410+
break;
23872411
default:
23882412
break;
23892413
}

0 commit comments

Comments
 (0)