Skip to content

Commit

Permalink
fix: After the SFTP network was disconnected, dde-file-manager froze,…
Browse files Browse the repository at this point in the history
…add GVFS file detection and improve symlink handling

- Add isGvfsFile utility function to detect GVFS paths
- Update symlink handling in DLocalHelper to avoid stat calls on GVFS files
- Add regex pattern to match GVFS paths including /run/user/*/gvfs, /root/.gvfs, and /media/*/smbmounts

This change improves performance by preventing unnecessary stat calls on GVFS symlinks
and adds better support for GVFS file system detection.

Log: After the SFTP network was disconnected, dde-file-manager froze
Bug: https://pms.uniontech.com/bug-view-278533.html
  • Loading branch information
liyigang1 committed Nov 7, 2024
1 parent c81894c commit a724bde
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/dfm-io/dfm-io/dfmio_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class DFMUtils
static int syncTrashCount();
static qint64 deviceBytesFree(const QUrl &url);
static bool supportTrash(const QUrl &url);
static bool isGvfsFile(const QUrl &url);

private:
static QMap<QString, QString>
Expand Down
13 changes: 13 additions & 0 deletions src/dfm-io/dfm-io/dfmio_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,19 @@ bool dfmio::DFMUtils::supportTrash(const QUrl &url)
return true;
}

bool DFMUtils::isGvfsFile(const QUrl &url)
{
if (!url.isValid())
return false;

const QString &path = url.toLocalFile();
static const QString gvfsMatch { "(^/run/user/\\d+/gvfs/|^/root/.gvfs/|^/media/[\\s\\S]*/smbmounts)" };
// TODO(xust) /media/$USER/smbmounts might be changed in the future.
QRegularExpression re { gvfsMatch };
QRegularExpressionMatch match { re.match(path) };
return match.hasMatch();
}

QMap<QString, QString> DFMUtils::fstabBindInfo()
{
static QMutex mutex;
Expand Down
9 changes: 6 additions & 3 deletions src/dfm-io/dfm-io/utils/dlocalhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,14 +907,17 @@ QSharedPointer<DEnumerator::SortFileInfo> DLocalHelper::createSortFileInfo(const
if (size > 0) {
QString symlinkTagetPath = QString::fromUtf8(buffer, static_cast<int>(size));
sortPointer->symlinkUrl = QUrl::fromLocalFile(symlinkTagetPath);
struct stat st;
if (stat(symlinkTagetPath.toStdString().c_str(),&st) == 0)
sortPointer->isDir = S_ISDIR(st.st_mode);
}
} else {
sortPointer->isDir = S_ISDIR(ent->fts_statp->st_mode);
}

if (sortPointer->symlinkUrl.isValid() && !DFMUtils::isGvfsFile(sortPointer->symlinkUrl)) {
struct stat st;
if (stat(sortPointer->symlinkUrl.path().toStdString().c_str(),&st) == 0)
sortPointer->isDir = S_ISDIR(st.st_mode);
}

sortPointer->isFile = !sortPointer->isDir;
sortPointer->isHide = name.startsWith(".") ? true : hidList.contains(name);
sortPointer->isReadable = ent->fts_statp->st_mode & S_IREAD;
Expand Down
1 change: 1 addition & 0 deletions src/dfm-io/dfm-io/utils/dlocalhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <dfm-io/dfmio_global.h>
#include <dfm-io/dfileinfo.h>
#include <dfm-io/denumerator.h>
#include <dfm-io/dfmio_utils.h>

#include <gio/gio.h>

Expand Down

0 comments on commit a724bde

Please sign in to comment.