Skip to content

Commit ac46223

Browse files
pppanghu77deepin-bot[bot]
authored andcommitted
fix: Refactor long file name handling in common interface
Renamed functions and updated logic to improve clarity and consistency in handling long file names across the codebase. The function `isSubpathOfDlnfs` is now `isSubpathOfLnfs`, and `findDlnfsPath` has been changed to `findLnfsPath`. This refactoring enhances the readability of the code and ensures that the correct file system types are checked for long file name support. Log: Refactor long file name handling in common interface Bug: https://pms.uniontech.com/bug-view-326015.html
1 parent 6a053bd commit ac46223

File tree

8 files changed

+52
-24
lines changed

8 files changed

+52
-24
lines changed

3rdparty/interface/archiveinterface/cliinterface.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const
104104
});
105105
return PFT_Nomral;
106106
}
107-
bool bDlnfs = m_common->isSubpathOfDlnfs(options.strTargetPath);
108-
setProperty("dlnfs", bDlnfs);
107+
bool bLnfs = m_common->isSubpathOfLnfs(options.strTargetPath);
108+
setProperty("lnfs", bLnfs);
109109
ArchiveData arcData = DataManager::get_instance().archiveData();
110110
m_files = files;
111111
m_extractOptions = options;
112112

113-
if (!bDlnfs) {
113+
if (!bLnfs) {
114114
if (arcData.listRootEntry.isEmpty() && options.qSize < FILE_MAX_SIZE) {
115115
emit signalprogress(1);
116116
setProperty("list", "tmpList");
@@ -119,10 +119,10 @@ PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const
119119
return PFT_Nomral;
120120
}
121121
}
122-
return extractFiles(files, options, bDlnfs);
122+
return extractFiles(files, options, bLnfs);
123123
}
124124

125-
PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const ExtractionOptions &options, bool bDlnfs)
125+
PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const ExtractionOptions &options, bool bLnfs)
126126
{
127127
ArchiveData arcData = DataManager::get_instance().archiveData();
128128
setProperty("list", "");
@@ -187,7 +187,7 @@ PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const
187187
}
188188
}
189189
//长文件解压
190-
if (!bDlnfs) {
190+
if (!bLnfs) {
191191
for (FileEntry entry : m_files) {
192192
if (NAME_MAX < entry.strFileName.toLocal8Bit().length() || NAME_MAX < entry.strFullPath.toLocal8Bit().length()) {
193193
bHandleLongName = true;
@@ -236,7 +236,7 @@ PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const
236236
} else {
237237
password = options.password;
238238
}
239-
if (!bDlnfs) {
239+
if (!bLnfs) {
240240
for (QMap<QString, FileEntry>::const_iterator iter = arcData.mapFileEntry.begin(); iter != arcData.mapFileEntry.end(); iter++) {
241241
if (NAME_MAX < iter.value().strFileName.toLocal8Bit().length()) {
242242
bHandleLongName = true;
@@ -751,7 +751,7 @@ bool CliInterface::runProcess(const QString &programName, const QStringList &arg
751751
emit signalFinished(PFT_Error);
752752
}
753753
deleteProcess();
754-
extractFiles(m_files, m_extractOptions, property("dlnfs").toBool());
754+
extractFiles(m_files, m_extractOptions, property("lnfs").toBool());
755755
}
756756
});
757757
}

3rdparty/interface/archiveinterface/cliinterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class CliInterface : public ReadWriteArchiveInterface
182182
/**
183183
* @brief extractFiles 业务解压
184184
*/
185-
PluginFinishType extractFiles(const QList<FileEntry> &files, const ExtractionOptions &options, bool bDlnfs);
185+
PluginFinishType extractFiles(const QList<FileEntry> &files, const ExtractionOptions &options, bool bLnfs);
186186

187187
private:
188188
/**

3rdparty/interface/common.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,9 @@ QString Common::handleLongNameforPath(const QString &strFilePath, const QString
419419
return sDir;
420420
}
421421

422-
bool Common::isSubpathOfDlnfs(const QString &path)
422+
bool Common::isSubpathOfLnfs(const QString &path)
423423
{
424-
return findDlnfsPath(path, [](const QString &target, const QString &compare) {
424+
return findLnfsPath(path, [](const QString &target, const QString &compare) {
425425
return target.startsWith(compare);
426426
});
427427
}
@@ -464,7 +464,7 @@ bool Common::isSupportSeek(QString sFileName)
464464
return false;
465465
}
466466

467-
bool Common::findDlnfsPath(const QString &target, Compare func)
467+
bool Common::findLnfsPath(const QString &target, Compare func)
468468
{
469469
Q_ASSERT(func);
470470
libmnt_table *tab { mnt_new_table() };
@@ -486,13 +486,29 @@ bool Common::findDlnfsPath(const QString &target, Compare func)
486486
while (mnt_table_next_fs(tab, iter, &fs) == 0) {
487487
if (!fs)
488488
continue;
489-
qInfo() << unifyPath(mnt_fs_get_target(fs));
490-
if (strcmp("dlnfs", mnt_fs_get_source(fs)) == 0) {
491-
QString mpt = unifyPath(mnt_fs_get_target(fs));
492-
if (func(unifyPath(target), mpt))
489+
490+
const char* fsType = mnt_fs_get_fstype(fs);
491+
const char* mountPoint = mnt_fs_get_target(fs);
492+
493+
if (!mountPoint)
494+
continue;
495+
496+
QString fsTypeStr = fsType ? QString(fsType) : "";
497+
QString mountPointStr = unifyPath(mountPoint);
498+
499+
qInfo() << "Checking filesystem - Type:" << fsTypeStr
500+
<< "Mount:" << mountPointStr;
501+
502+
// 检查是否是支持长文件名的文件系统类型
503+
bool isLongFileNameFS = (fsTypeStr == "fuse.dlnfs") ||
504+
(fsTypeStr == "ulnfs");
505+
506+
if (isLongFileNameFS) {
507+
if (func(unifyPath(target), mountPointStr)) {
493508
if (tab) mnt_free_table(tab);
494509
if (iter) mnt_free_iter(iter);
495510
return true;
511+
}
496512
}
497513
}
498514

3rdparty/interface/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ class Common: public QObject
4040
//长文件夹处理
4141
QString handleLongNameforPath(const QString &strFilePath, const QString &entryName, QMap<QString, int> &mapLongDirName, QMap<QString, int> &mapRealDirValue);
4242
//当前文件系统是否支持长文件
43-
bool isSubpathOfDlnfs(const QString &path);
43+
bool isSubpathOfLnfs(const QString &path);
4444
/**
4545
* @brief isSupportSeek 是否支持seek操作
4646
* @param sFileName 文件名
4747
*/
4848
bool isSupportSeek(QString sFileName);
4949
private:
5050
//通过mount对应方法判断文件系统是否支持长文件
51-
bool findDlnfsPath(const QString &target, Compare func);
51+
bool findLnfsPath(const QString &target, Compare func);
5252
};
5353

5454
/**

3rdparty/libarchive/libarchive/libarchiveplugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ PluginFinishType LibarchivePlugin::extractFiles(const QList<FileEntry> &files, c
168168
struct archive_entry *entry = nullptr;
169169

170170
QString extractDst;
171-
bool bDlnfs = m_common->isSubpathOfDlnfs(options.strTargetPath);
171+
bool bLnfs = m_common->isSubpathOfLnfs(options.strTargetPath);
172172
// Iterate through all entries in archive.
173173
int iIndex = 0; // 存储索引值
174174
while (!QThread::currentThread()->isInterruptionRequested() && (archive_read_next_header(m_archiveReader.data(), &entry) == ARCHIVE_OK)) {
@@ -265,7 +265,7 @@ PluginFinishType LibarchivePlugin::extractFiles(const QList<FileEntry> &files, c
265265
bool bLongName = false;
266266
QString tempFilePathName;
267267
QString strOriginName = entryName;
268-
if(!bDlnfs) {
268+
if(!bLnfs) {
269269
QString sDir = m_common->handleLongNameforPath(strFilePath, entryName, m_mapLongDirName, m_mapRealDirValue);
270270
if(sDir.length() > 0) {
271271
strFilePath = sDir.endsWith(QDir::separator())?sDir.left(sDir.length() -1):sDir;

3rdparty/libzipplugin/libzipplugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ PluginFinishType LibzipPlugin::extractFiles(const QList<FileEntry> &files, const
161161
} else {
162162
m_dScaleSize = 100.0 / options.qSize;
163163
}
164-
m_bDlnfs = m_common->isSubpathOfDlnfs(options.strTargetPath);
164+
m_bLnfs = m_common->isSubpathOfLnfs(options.strTargetPath);
165165

166166
// 执行解压操作
167167
bool bHandleLongName = false;
@@ -812,7 +812,7 @@ ErrorType LibzipPlugin::extractEntry(zip_t *archive, zip_int64_t index, const Ex
812812
}
813813

814814
QString tempFilePathName;
815-
if(!m_bDlnfs) {
815+
if(!m_bLnfs) {
816816
QString sDir = m_common->handleLongNameforPath(strFilePath, strFileName, m_mapLongDirName, m_mapRealDirValue);
817817
if(sDir.length() > 0) {
818818
strFilePath = sDir.endsWith(QDir::separator())?sDir.left(sDir.length() -1):sDir;

3rdparty/libzipplugin/libzipplugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class LibzipPlugin : public ReadWriteArchiveInterface
197197
QMap<QString, int> m_mapLongDirName; // 长文件夹统计
198198
QMap<QString, int> m_mapRealDirValue; // 长文件真实文件统计
199199
QSet<QString> m_setLongName; // 存储被截取之后的文件名称(包含001之类的)
200-
bool m_bDlnfs = false; //文件系统是否支持长文件
200+
bool m_bLnfs = false; //文件系统是否支持长文件名
201201
};
202202

203203
#endif // LIBZIPPLUGIN_H

src/source/common/uitools.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,19 @@ bool UiTools::isLocalDeviceFile(const QString &strFileName)
415415
{
416416
QStorageInfo info(strFileName);
417417
QString sDevice = info.device();
418-
return sDevice.startsWith("/dev/") || sDevice.startsWith("dlnfs"); //长文件名开启后以dlnfs方式挂载
418+
QString sFileSystemType = info.fileSystemType();
419+
420+
// 检查传统的本地设备(以 /dev/ 开头)
421+
if (sDevice.startsWith("/dev/")) {
422+
return true;
423+
}
424+
425+
// 检查长文件名文件系统类型
426+
if (sFileSystemType == "fuse.dlnfs" || sFileSystemType == "ulnfs") {
427+
return true;
428+
}
429+
430+
return false;
419431
}
420432

421433
QStringList UiTools::removeSameFileName(const QStringList &listFiles)

0 commit comments

Comments
 (0)