Skip to content

Commit 350b81d

Browse files
GongHeng2017deepin-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 6fa837f commit 350b81d

File tree

8 files changed

+51
-26
lines changed

8 files changed

+51
-26
lines changed

3rdparty/interface/archiveinterface/cliinterface.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const
110110
return PFT_Nomral;
111111
}
112112

113-
bool bDlnfs = m_common->isSubpathOfDlnfs(options.strTargetPath);
114-
setProperty("dlnfs", bDlnfs);
113+
bool bLnfs = m_common->isSubpathOfLnfs(options.strTargetPath);
114+
setProperty("lnfs", bLnfs);
115115
ArchiveData arcData = DataManager::get_instance().archiveData();
116116
m_files = files;
117117
m_extractOptions = options;
118118

119-
if (!bDlnfs) {
119+
if (!bLnfs) {
120120
if (arcData.listRootEntry.isEmpty() && options.qSize < FILE_MAX_SIZE) {
121121
emit signalprogress(1);
122122
setProperty("list", "tmpList");
@@ -125,10 +125,10 @@ PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const
125125
return PFT_Nomral;
126126
}
127127
}
128-
return extractFiles(files, options, bDlnfs);
128+
return extractFiles(files, options, bLnfs);
129129
}
130130

131-
PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const ExtractionOptions &options, bool bDlnfs)
131+
PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const ExtractionOptions &options, bool bLnfs)
132132
{
133133
ArchiveData arcData = DataManager::get_instance().archiveData();
134134
setProperty("list", "");
@@ -193,7 +193,7 @@ PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const
193193
}
194194
}
195195
//长文件解压
196-
if (!bDlnfs) {
196+
if (!bLnfs) {
197197
for (FileEntry entry : m_files) {
198198
if (NAME_MAX < entry.strFileName.toLocal8Bit().length() || NAME_MAX < entry.strFullPath.toLocal8Bit().length()) {
199199
bHandleLongName = true;
@@ -242,7 +242,7 @@ PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const
242242
} else {
243243
password = options.password;
244244
}
245-
if (!bDlnfs) {
245+
if (!bLnfs) {
246246
for (QMap<QString, FileEntry>::const_iterator iter = arcData.mapFileEntry.begin(); iter != arcData.mapFileEntry.end(); iter++) {
247247
if (NAME_MAX < iter.value().strFileName.toLocal8Bit().length()) {
248248
bHandleLongName = true;
@@ -764,7 +764,7 @@ bool CliInterface::runProcess(const QString &programName, const QStringList &arg
764764
emit signalFinished(PFT_Error);
765765
}
766766
deleteProcess();
767-
extractFiles(m_files, m_extractOptions, property("dlnfs").toBool());
767+
extractFiles(m_files, m_extractOptions, property("lnfs").toBool());
768768
}
769769
});
770770
}

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: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,9 @@ QString Common::handleLongNameforPath(const QString &strFilePath, const QString
439439
return sDir;
440440
}
441441

442-
bool Common::isSubpathOfDlnfs(const QString &path)
442+
bool Common::isSubpathOfLnfs(const QString &path)
443443
{
444-
return findDlnfsPath(path, [](const QString &target, const QString &compare) {
444+
return findLnfsPath(path, [](const QString &target, const QString &compare) {
445445
return target.startsWith(compare);
446446
});
447447
}
@@ -484,7 +484,7 @@ bool Common::isSupportSeek(QString sFileName)
484484
return false;
485485
}
486486

487-
bool Common::findDlnfsPath(const QString &target, Compare func)
487+
bool Common::findLnfsPath(const QString &target, Compare func)
488488
{
489489
Q_ASSERT(func);
490490
libmnt_table *tab { mnt_new_table() };
@@ -506,13 +506,28 @@ bool Common::findDlnfsPath(const QString &target, Compare func)
506506
while (mnt_table_next_fs(tab, iter, &fs) == 0) {
507507
if (!fs)
508508
continue;
509-
qInfo() << unifyPath(mnt_fs_get_target(fs));
510-
if (strcmp("dlnfs", mnt_fs_get_source(fs)) == 0) {
511-
QString mpt = unifyPath(mnt_fs_get_target(fs));
512-
if (func(unifyPath(target), mpt))
509+
const char* fsType = mnt_fs_get_fstype(fs);
510+
const char* mountPoint = mnt_fs_get_target(fs);
511+
512+
if (!mountPoint)
513+
continue;
514+
515+
QString fsTypeStr = fsType ? QString(fsType) : "";
516+
QString mountPointStr = unifyPath(mountPoint);
517+
518+
qInfo() << "Checking filesystem - Type:" << fsTypeStr
519+
<< "Mount:" << mountPointStr;
520+
521+
// 检查是否是支持长文件名的文件系统类型
522+
bool isLongFileNameFS = (fsTypeStr == "fuse.dlnfs") ||
523+
(fsTypeStr == "ulnfs");
524+
525+
if (isLongFileNameFS) {
526+
if (func(unifyPath(target), mountPointStr)) {
513527
if (tab) mnt_free_table(tab);
514528
if (iter) mnt_free_iter(iter);
515529
return true;
530+
}
516531
}
517532
}
518533

3rdparty/interface/common.h

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

5555
/**

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
@@ -164,7 +164,7 @@ PluginFinishType LibzipPlugin::extractFiles(const QList<FileEntry> &files, const
164164
} else {
165165
m_dScaleSize = 100.0 / options.qSize;
166166
}
167-
m_bDlnfs = m_common->isSubpathOfDlnfs(options.strTargetPath);
167+
m_bLnfs = m_common->isSubpathOfLnfs(options.strTargetPath);
168168

169169
// 执行解压操作
170170
bool bHandleLongName = false;
@@ -821,7 +821,7 @@ ErrorType LibzipPlugin::extractEntry(zip_t *archive, zip_int64_t index, const Ex
821821
}
822822

823823
QString tempFilePathName;
824-
if(!m_bDlnfs) {
824+
if(!m_bLnfs) {
825825
QString sDir = m_common->handleLongNameforPath(strFilePath, strFileName, m_mapLongDirName, m_mapRealDirValue);
826826
if(sDir.length() > 0) {
827827
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,19 @@ bool UiTools::isLocalDeviceFile(const QString &strFileName)
506506
qDebug() << "Checking if file is on local device:" << strFileName;
507507
QStorageInfo info(strFileName);
508508
QString sDevice = info.device();
509-
bool result = sDevice.startsWith("/dev/") || sDevice.startsWith("dlnfs"); //长文件名开启后以dlnfs方式挂载
510-
qDebug() << "Device:" << sDevice << "is local:" << result;
511-
return result;
509+
QString sFileSystemType = info.fileSystemType();
510+
511+
// 检查传统的本地设备(以 /dev/ 开头)
512+
if (sDevice.startsWith("/dev/")) {
513+
return true;
514+
}
515+
516+
// 检查长文件名文件系统类型
517+
if (sFileSystemType == "fuse.dlnfs" || sFileSystemType == "ulnfs") {
518+
return true;
519+
}
520+
521+
return false;
512522
}
513523

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

0 commit comments

Comments
 (0)