Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions 3rdparty/interface/archiveinterface/cliinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const
return PFT_Nomral;
}

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

if (!bDlnfs) {
if (!bLnfs) {
if (arcData.listRootEntry.isEmpty() && options.qSize < FILE_MAX_SIZE) {
emit signalprogress(1);
setProperty("list", "tmpList");
Expand All @@ -125,10 +125,10 @@ PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const
return PFT_Nomral;
}
}
return extractFiles(files, options, bDlnfs);
return extractFiles(files, options, bLnfs);
}

PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const ExtractionOptions &options, bool bDlnfs)
PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const ExtractionOptions &options, bool bLnfs)
{
ArchiveData arcData = DataManager::get_instance().archiveData();
setProperty("list", "");
Expand Down Expand Up @@ -193,7 +193,7 @@ PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const
}
}
//长文件解压
if (!bDlnfs) {
if (!bLnfs) {
for (FileEntry entry : m_files) {
if (NAME_MAX < entry.strFileName.toLocal8Bit().length() || NAME_MAX < entry.strFullPath.toLocal8Bit().length()) {
bHandleLongName = true;
Expand Down Expand Up @@ -242,7 +242,7 @@ PluginFinishType CliInterface::extractFiles(const QList<FileEntry> &files, const
} else {
password = options.password;
}
if (!bDlnfs) {
if (!bLnfs) {
for (QMap<QString, FileEntry>::const_iterator iter = arcData.mapFileEntry.begin(); iter != arcData.mapFileEntry.end(); iter++) {
if (NAME_MAX < iter.value().strFileName.toLocal8Bit().length()) {
bHandleLongName = true;
Expand Down Expand Up @@ -764,7 +764,7 @@ bool CliInterface::runProcess(const QString &programName, const QStringList &arg
emit signalFinished(PFT_Error);
}
deleteProcess();
extractFiles(m_files, m_extractOptions, property("dlnfs").toBool());
extractFiles(m_files, m_extractOptions, property("lnfs").toBool());
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/interface/archiveinterface/cliinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class CliInterface : public ReadWriteArchiveInterface
/**
* @brief extractFiles 业务解压
*/
PluginFinishType extractFiles(const QList<FileEntry> &files, const ExtractionOptions &options, bool bDlnfs);
PluginFinishType extractFiles(const QList<FileEntry> &files, const ExtractionOptions &options, bool bLnfs);

private:
/**
Expand Down
29 changes: 22 additions & 7 deletions 3rdparty/interface/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ QString Common::handleLongNameforPath(const QString &strFilePath, const QString
return sDir;
}

bool Common::isSubpathOfDlnfs(const QString &path)
bool Common::isSubpathOfLnfs(const QString &path)
{
return findDlnfsPath(path, [](const QString &target, const QString &compare) {
return findLnfsPath(path, [](const QString &target, const QString &compare) {
return target.startsWith(compare);
});
}
Expand Down Expand Up @@ -484,7 +484,7 @@ bool Common::isSupportSeek(QString sFileName)
return false;
}

bool Common::findDlnfsPath(const QString &target, Compare func)
bool Common::findLnfsPath(const QString &target, Compare func)
Copy link

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 loop to use RAII for resource management, move invariant computations outside the loop, and simplify type comparisons to reduce complexity.

You can dramatically flatten this by

• pulling unifyPath(target) out of the loop
• comparing raw const char* against a tiny static list (no QString temp)
• using RAII for your table/iter so you don’t need to sprinkle frees everywhere
• removing the per-fs logging (or guard it behind a DEBUG-only flag)

For example:

// small RAII wrappers for auto‐freeing
struct MntTable {
    libmnt_table *ptr{ mnt_new_table() };
    ~MntTable() { if (ptr) mnt_free_table(ptr); }
};
struct MntIter {
    libmnt_iter *ptr{ mnt_new_iter(MNT_ITER_BACKWARD) };
    ~MntIter() { if (ptr) mnt_free_iter(ptr); }
};

bool Common::findLnfsPath(const QString &target, Compare func) {
    Q_ASSERT(func);
    MntTable table;
    MntIter iter;
    if (mnt_table_parse_mtab(table.ptr, nullptr) != 0)
        return false;

    const QString targetPath = unifyPath(target);
    static constexpr const char* kLnfsTypes[] = {"fuse.dlnfs", "ulnfs"};

    libmnt_fs *fs = nullptr;
    while (mnt_table_next_fs(table.ptr, iter.ptr, &fs) == 0 && fs) {
        const char* mountPoint = mnt_fs_get_target(fs);
        if (!mountPoint) continue;

        // raw C‐string compare, no QString temp
        for (auto type : kLnfsTypes) {
            if (strcmp(mnt_fs_get_fstype(fs), type) == 0 &&
                func(targetPath, unifyPath(mountPoint))) {
                return true;
            }
        }
    }
    return false;
}

This

  1. moves the unifyPath(target) call out of the hot loop
  2. drops all QString conversions of fstype into raw strcmp
  3. eliminates deep nesting by inverting and combining conditions
  4. uses RAII (MntTable/MntIter) so you never forget a free—or need to null-check before freeing.

{
Q_ASSERT(func);
libmnt_table *tab { mnt_new_table() };
Expand All @@ -506,13 +506,28 @@ bool Common::findDlnfsPath(const QString &target, Compare func)
while (mnt_table_next_fs(tab, iter, &fs) == 0) {
if (!fs)
continue;
qInfo() << unifyPath(mnt_fs_get_target(fs));
if (strcmp("dlnfs", mnt_fs_get_source(fs)) == 0) {
QString mpt = unifyPath(mnt_fs_get_target(fs));
if (func(unifyPath(target), mpt))
const char* fsType = mnt_fs_get_fstype(fs);
const char* mountPoint = mnt_fs_get_target(fs);

if (!mountPoint)
continue;

QString fsTypeStr = fsType ? QString(fsType) : "";
QString mountPointStr = unifyPath(mountPoint);

qInfo() << "Checking filesystem - Type:" << fsTypeStr
<< "Mount:" << mountPointStr;

// 检查是否是支持长文件名的文件系统类型
bool isLongFileNameFS = (fsTypeStr == "fuse.dlnfs") ||
(fsTypeStr == "ulnfs");

if (isLongFileNameFS) {
if (func(unifyPath(target), mountPointStr)) {
if (tab) mnt_free_table(tab);
if (iter) mnt_free_iter(iter);
return true;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions 3rdparty/interface/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class Common: public QObject
//长文件夹处理
QString handleLongNameforPath(const QString &strFilePath, const QString &entryName, QMap<QString, int> &mapLongDirName, QMap<QString, int> &mapRealDirValue);
//当前文件系统是否支持长文件
bool isSubpathOfDlnfs(const QString &path);
bool isSubpathOfLnfs(const QString &path);
/**
* @brief isSupportSeek 是否支持seek操作
* @param sFileName 文件名
*/
bool isSupportSeek(QString sFileName);
private:
//通过mount对应方法判断文件系统是否支持长文件
bool findDlnfsPath(const QString &target, Compare func);
bool findLnfsPath(const QString &target, Compare func);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions 3rdparty/libarchive/libarchive/libarchiveplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ PluginFinishType LibarchivePlugin::extractFiles(const QList<FileEntry> &files, c
struct archive_entry *entry = nullptr;

QString extractDst;
bool bDlnfs = m_common->isSubpathOfDlnfs(options.strTargetPath);
bool bLnfs = m_common->isSubpathOfLnfs(options.strTargetPath);
// Iterate through all entries in archive.
int iIndex = 0; // 存储索引值
while (!QThread::currentThread()->isInterruptionRequested() && (archive_read_next_header(m_archiveReader.data(), &entry) == ARCHIVE_OK)) {
Expand Down Expand Up @@ -265,7 +265,7 @@ PluginFinishType LibarchivePlugin::extractFiles(const QList<FileEntry> &files, c
bool bLongName = false;
QString tempFilePathName;
QString strOriginName = entryName;
if(!bDlnfs) {
if(!bLnfs) {
QString sDir = m_common->handleLongNameforPath(strFilePath, entryName, m_mapLongDirName, m_mapRealDirValue);
if(sDir.length() > 0) {
strFilePath = sDir.endsWith(QDir::separator())?sDir.left(sDir.length() -1):sDir;
Expand Down
4 changes: 2 additions & 2 deletions 3rdparty/libzipplugin/libzipplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ PluginFinishType LibzipPlugin::extractFiles(const QList<FileEntry> &files, const
} else {
m_dScaleSize = 100.0 / options.qSize;
}
m_bDlnfs = m_common->isSubpathOfDlnfs(options.strTargetPath);
m_bLnfs = m_common->isSubpathOfLnfs(options.strTargetPath);

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

QString tempFilePathName;
if(!m_bDlnfs) {
if(!m_bLnfs) {
QString sDir = m_common->handleLongNameforPath(strFilePath, strFileName, m_mapLongDirName, m_mapRealDirValue);
if(sDir.length() > 0) {
strFilePath = sDir.endsWith(QDir::separator())?sDir.left(sDir.length() -1):sDir;
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/libzipplugin/libzipplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class LibzipPlugin : public ReadWriteArchiveInterface
QMap<QString, int> m_mapLongDirName; // 长文件夹统计
QMap<QString, int> m_mapRealDirValue; // 长文件真实文件统计
QSet<QString> m_setLongName; // 存储被截取之后的文件名称(包含001之类的)
bool m_bDlnfs = false; //文件系统是否支持长文件
bool m_bLnfs = false; //文件系统是否支持长文件
};

#endif // LIBZIPPLUGIN_H
16 changes: 13 additions & 3 deletions src/source/common/uitools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,19 @@ bool UiTools::isLocalDeviceFile(const QString &strFileName)
qDebug() << "Checking if file is on local device:" << strFileName;
QStorageInfo info(strFileName);
QString sDevice = info.device();
bool result = sDevice.startsWith("/dev/") || sDevice.startsWith("dlnfs"); //长文件名开启后以dlnfs方式挂载
qDebug() << "Device:" << sDevice << "is local:" << result;
return result;
QString sFileSystemType = info.fileSystemType();

// 检查传统的本地设备(以 /dev/ 开头)
if (sDevice.startsWith("/dev/")) {
return true;
}

// 检查长文件名文件系统类型
if (sFileSystemType == "fuse.dlnfs" || sFileSystemType == "ulnfs") {
return true;
}

return false;
}

QStringList UiTools::removeSameFileName(const QStringList &listFiles)
Expand Down