Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support smb mount path with /run prefix #2484

Merged
merged 5 commits into from
Dec 12, 2024
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
8 changes: 7 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Depends:
libqt6sql6-sqlite,
qt6-translations-l10n,
libimageeditor6 | hello
Conflicts: dde-workspace (<< 2.90.5), dde-file-manager-oem
Conflicts: dde-workspace (<< 2.90.5), dde-file-manager-oem, dde-desktop-plugins
Replaces: dde-file-manager-oem, dde-file-manager (<< 6.0.1), dde-desktop-plugins
Recommends: qt5dxcb-plugin, deepin-screensaver, dcc-wallpapersetting-plugin
Description: deepin desktop-environment - desktop module
Expand Down Expand Up @@ -109,6 +109,11 @@ Replaces: dde-file-manager-oem, dde-desktop (<< 6.0.1),
dde-file-manager-plugins,
dde-file-manager-daemon-plugins,
dde-file-manager-common-plugins
Conflicts: dde-file-manager-preview,
dde-file-manager-preview-plugins,
dde-file-manager-plugins,
dde-file-manager-daemon-plugins,
dde-file-manager-common-plugins
Recommends: dde-qt5integration, avfs, samba, deepin-anything-server
Description: File manager front end
File manager front-end of Deepin OS
Expand All @@ -127,6 +132,7 @@ Multi-Arch: same
Description: DDE File Manager core librarys
This package contains the shared libraries.
Replaces: dfmplugin-disk-encrypt
Conflicts: dfmplugin-disk-encrypt

Package: dde-disk-mount-plugin
Architecture: any
Expand Down
72 changes: 12 additions & 60 deletions src/dfm-base/base/device/deviceutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <dfm-base/utils/networkutils.h>
#include <dfm-base/base/device/deviceproxymanager.h>
#include <dfm-base/dbusservice/global_server_defines.h>
#include <dfm-base/utils/protocolutils.h>

#include <dfm-io/dfile.h>
#include <dfm-burn/dburn_global.h>
Expand Down Expand Up @@ -75,7 +76,7 @@ QUrl DeviceUtils::getSambaFileUriFromNative(const QUrl &url)
if (!url.isValid())
return QUrl();

if (!DeviceUtils::isSamba(url))
if (!ProtocolUtils::isSMBFile(url))
return url;

QUrl smbUrl;
Expand All @@ -93,7 +94,7 @@ QUrl DeviceUtils::getSambaFileUriFromNative(const QUrl &url)
// /root/.gvfs/smb-share...../helloworld.txt
// /media/user/smbmounts/smb-share...../helloworld.txt
// ======> helloworld.txt
static const QRegularExpression prefix(R"(^/run/user/.*/gvfs/[^/]*/|^/root/.gvfs/[^/]*/|^/media/.*/smbmounts/[^/]*/)");
static const QRegularExpression prefix(R"(^/run/user/.*/gvfs/[^/]*/|^/root/.gvfs/[^/]*/|^/(?:run/)?media/.*/smbmounts/[^/]*/)");
QString fileName = fullPath.remove(prefix);
fileName.chop(1); // remove last '/'.

Expand Down Expand Up @@ -270,62 +271,25 @@ bool DeviceUtils::isPWUserspaceOpticalDiscDev(const QString &dev)
return isPWOpticalDiscDev(dev);
}

bool DeviceUtils::isSamba(const QUrl &url)
{
if (url.scheme() == Global::Scheme::kSmb)
return true;
static const QString smbMatch { "(^/run/user/\\d+/gvfs/smb|^/root/\\.gvfs/smb|^/media/[\\s\\S]*/smbmounts)" }; // TODO(xust) /media/$USER/smbmounts might be changed in the future.}
return hasMatch(url.path(), smbMatch);
}

bool DeviceUtils::isFtp(const QUrl &url)
{
static const QString smbMatch { "(^/run/user/\\d+/gvfs/s?ftp|^/root/\\.gvfs/s?ftp)" };
return hasMatch(url.path(), smbMatch);
}

bool DeviceUtils::isSftp(const QUrl &url)
{
static const QString smbMatch { "(^/run/user/\\d+/gvfs/sftp|^/root/\\.gvfs/sftp)" };
return hasMatch(url.path(), smbMatch);
}

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

const QString &path = url.toLocalFile();
static const QString gvfsMatch { R"(^/run/user/\d+/gvfs/mtp:host|^/root/.gvfs/mtp:host)" };
QRegularExpression re { gvfsMatch };
QRegularExpressionMatch match { re.match(path) };
return match.hasMatch();
}

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

return !isMtpFile(url);
return !ProtocolUtils::isMTPFile(url);
}

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

return !isMtpFile(url);
}

bool DeviceUtils::isExternalBlock(const QUrl &url)
{
return DeviceProxyManager::instance()->isFileOfExternalBlockMounts(url.path());
return !ProtocolUtils::isMTPFile(url);
}

QUrl DeviceUtils::parseNetSourceUrl(const QUrl &target)
{
if (!isSamba(target) && !isFtp(target))
if (!ProtocolUtils::isSMBFile(target) && !ProtocolUtils::isFTPFile(target))
return {};

QString host, port;
Expand All @@ -334,7 +298,7 @@ QUrl DeviceUtils::parseNetSourceUrl(const QUrl &target)
return {};

QString protocol, share;
if (isSamba(target)) {
if (ProtocolUtils::isSMBFile(target)) {
protocol = "smb";
static const QRegularExpression regxSmb(R"(,share=([^,/]*))");
auto match = regxSmb.match(target.path());
Expand All @@ -343,10 +307,10 @@ QUrl DeviceUtils::parseNetSourceUrl(const QUrl &target)
else
return {};
} else {
protocol = isSftp(target) ? "sftp" : "ftp";
protocol = ProtocolUtils::isSFTPFile(target) ? "sftp" : "ftp";
}

static const QRegularExpression prefix(R"(^/run/user/.*/gvfs/[^/]*|^/media/.*/smbmounts/[^/]*)");
static const QRegularExpression prefix(R"(^/run/user/.*/gvfs/[^/]*|^/(?:run/)?media/.*/smbmounts/[^/]*)");
QString dirPath = target.path();
dirPath.remove(prefix);
dirPath.prepend(share);
Expand Down Expand Up @@ -411,11 +375,12 @@ QString DeviceUtils::nameOfSystemDisk(const QVariantMap &datas)
QString mountPoint = clearInfo.value(kMountPoint, datas.value(kMountPoint)).toString();
QString label = clearInfo.value(kIdLabel, datas.value(kIdLabel)).toString();
qlonglong size = datas.value(kSizeTotal).toLongLong();
bool canPowerOff = datas.value(kCanPowerOff).toBool();

// get system disk name if there is no alias
if (mountPoint == "/")
return QObject::tr("System Disk");
if (!mountPoint.startsWith("/media/") && !mountPoint.isEmpty()) {
if (!canPowerOff && !mountPoint.isEmpty()) {
if (label.startsWith("_dde_data"))
return QObject::tr("Data Disk");
if (label.startsWith("_dde_"))
Expand Down Expand Up @@ -605,19 +570,6 @@ bool DeviceUtils::isMountPointOfDlnfs(const QString &path)
});
}

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

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

/*!
* \brief DeviceUtils::getLongestMountRootPath: get the mount root of a file `filePath`
* return `/home/` for `/home/helloworld.txt`, eg.
Expand Down Expand Up @@ -677,7 +629,7 @@ qint64 DeviceUtils::deviceBytesFree(const QUrl &url)

bool DeviceUtils::isUnmountSamba(const QUrl &url)
{
if (!isSamba(url))
if (!ProtocolUtils::isSMBFile(url))
return false;

return !DevProxyMng->isFileOfProtocolMounts(url.path());
Expand Down
6 changes: 0 additions & 6 deletions src/dfm-base/base/device/deviceutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ class DeviceUtils
static bool isPWOpticalDiscDev(const QString &dev);
static bool isPWUserspaceOpticalDiscDev(const QString &dev);

static bool isSamba(const QUrl &url);
static bool isFtp(const QUrl &url);
static bool isSftp(const QUrl &url);
static bool isMtpFile(const QUrl &url);
static bool supportDfmioCopyDevice(const QUrl &url);
static bool supportSetPermissionsDevice(const QUrl &url);
static bool isExternalBlock(const QUrl &url);
static QUrl parseNetSourceUrl(const QUrl &target);

static bool parseSmbInfo(const QString &smbPath, QString &host, QString &share, QString *port = nullptr);
Expand All @@ -73,7 +68,6 @@ class DeviceUtils

static bool isSubpathOfDlnfs(const QString &path);
static bool isMountPointOfDlnfs(const QString &path);
static bool isLowSpeedDevice(const QUrl &url);

static QString getLongestMountRootPath(const QString &filePath);

Expand Down
5 changes: 3 additions & 2 deletions src/dfm-base/base/device/private/devicehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <dfm-base/utils/universalutils.h>
#include <dfm-base/utils/dialogmanager.h>
#include <dfm-base/utils/networkutils.h>
#include <dfm-base/utils/protocolutils.h>

#include <DDesktopServices>
#include <dtkwidget_global.h>
Expand Down Expand Up @@ -375,7 +376,7 @@ void DeviceHelper::readOpticalInfo(QVariantMap &datas)
bool DeviceHelper::checkNetworkConnection(const QString &id)
{
QUrl url(id);
if (!(DeviceUtils::isSamba(url) || DeviceUtils::isSftp(url) || DeviceUtils::isFtp(url)))
if (!(ProtocolUtils::isSMBFile(url) || ProtocolUtils::isSFTPFile(url) || ProtocolUtils::isFTPFile(url)))
return true;

QString host, port;
Expand Down Expand Up @@ -414,7 +415,7 @@ QVariantMap DeviceHelper::makeFakeProtocolInfo(const QString &id)
fakeInfo[DeviceProperty::kDeviceIcon] = "folder-remote";
fakeInfo["fake"] = true;

if (DeviceUtils::isSamba(QUrl(path))) {
if (ProtocolUtils::isSMBFile(QUrl(path))) {
QString host, share;
if (DeviceUtils::parseSmbInfo(path, host, share))
fakeInfo[DeviceProperty::kDisplayName] = QObject::tr("%1 on %2").arg(share).arg(host);
Expand Down
6 changes: 3 additions & 3 deletions src/dfm-base/base/schemefactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include <dfm-base/base/schemefactory.h>
#include <dfm-base/utils/fileutils.h>
#include <dfm-base/utils/protocolutils.h>

namespace dfmbase {

Expand All @@ -19,15 +19,15 @@ QString InfoFactory::scheme(const QUrl &url)
if (scheme != Global::Scheme::kFile)
return scheme;

if (!FileUtils::isLocalDevice(url))
if (!ProtocolUtils::isLocalFile(url))
return Global::Scheme::kAsyncFile;

dfmio::DFileInfo dinfo(url);
if (!dinfo.attribute(dfmio::DFileInfo::AttributeID::kStandardIsSymlink).toBool())
return scheme;

auto targetPath = dinfo.attribute(dfmio::DFileInfo::AttributeID::kStandardSymlinkTarget).toString();
if (!targetPath.isEmpty() && !FileUtils::isLocalDevice(QUrl::fromLocalFile(targetPath)))
if (!targetPath.isEmpty() && !ProtocolUtils::isLocalFile(QUrl::fromLocalFile(targetPath)))
scheme = Global::Scheme::kAsyncFile;

return scheme;
Expand Down
25 changes: 13 additions & 12 deletions src/dfm-base/file/local/asyncfileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <dfm-base/mimetype/mimetypedisplaymanager.h>
#include <dfm-base/base/application/application.h>
#include <dfm-base/utils/thumbnail/thumbnailfactory.h>
#include <dfm-base/utils/protocolutils.h>

#include <dfm-io/dfmio_utils.h>
#include <dfm-io/dfileinfo.h>
Expand Down Expand Up @@ -130,10 +131,10 @@ QString AsyncFileInfo::nameOf(const NameInfoType type) const
return FileInfo::nameOf(type);
}
/*!
* \brief 获取文件路径,默认是文件全路径,此接口不会实现异步,全部使用Qurl去
* 处理或者字符串处理,这都比较快
* \param FileNameInfoType
*/
* \brief 获取文件路径,默认是文件全路径,此接口不会实现异步,全部使用Qurl去
* 处理或者字符串处理,这都比较快
* \param FileNameInfoType
*/
QString AsyncFileInfo::pathOf(const PathInfoType type) const
{
switch (type) {
Expand Down Expand Up @@ -168,7 +169,7 @@ QUrl AsyncFileInfo::urlOf(const UrlInfoType type) const
switch (type) {
case FileUrlInfoType::kRedirectedFileUrl:
return d->redirectedFileUrl();
case FileUrlInfoType::kOriginalUrl:{
case FileUrlInfoType::kOriginalUrl: {
auto originalUri = d->asyncAttribute(FileInfo::FileInfoAttributeID::kOriginalUri);
if (originalUri.isValid())
return QUrl(originalUri.toString());
Expand Down Expand Up @@ -218,7 +219,7 @@ bool AsyncFileInfo::canAttributes(const CanableInfoType type) const
case FileCanType::kCanRename:
return d->asyncAttribute(FileInfo::FileInfoAttributeID::kAccessCanRename).toBool();
case FileCanType::kCanHidden:
if (FileUtils::isGphotoFile(url))
if (ProtocolUtils::isGphotoFile(url))
return false;
return true;
default:
Expand Down Expand Up @@ -715,7 +716,7 @@ QIcon AsyncFileInfoPrivate::defaultIcon()
QString AsyncFileInfoPrivate::fileName() const
{
QString fileName = this->attribute(DFileInfo::AttributeID::kStandardName).toString();
if (fileName == R"(/)" && FileUtils::isGvfsFile(q->fileUrl()))
if (fileName == R"(/)" && ProtocolUtils::isRemoteFile(q->fileUrl()))
fileName = this->attribute(DFileInfo::AttributeID::kIdFilesystem).toString();
return fileName;
}
Expand Down Expand Up @@ -761,7 +762,7 @@ QString AsyncFileInfoPrivate::iconName() const
if (!list.isEmpty())
iconNameValue = list.first();
}
if (!FileUtils::isGvfsFile(q->fileUrl()) && iconNameValue.isEmpty())
if (!ProtocolUtils::isRemoteFile(q->fileUrl()) && iconNameValue.isEmpty())
iconNameValue = q->fileMimeType().iconName();
if (iconNameValue.isEmpty() && q->isAttributes(OptInfoType::kIsDir))
iconNameValue = "folder";
Expand All @@ -772,7 +773,7 @@ QString AsyncFileInfoPrivate::mimeTypeName() const
{
// At present, there is no dfmio library code. For temporary repair
// local file use the method on v20 to obtain mimeType
if (FileUtils::isGvfsFile(q->fileUrl())) {
if (ProtocolUtils::isRemoteFile(q->fileUrl())) {
return asyncAttribute(FileInfo::FileInfoAttributeID::kStandardContentType).toString();
}
return q->fileMimeType().name();
Expand All @@ -795,7 +796,7 @@ QString AsyncFileInfoPrivate::fileDisplayName() const
QString fileDisplayName = this->attribute(DFileInfo::AttributeID::kStandardDisplayName, &ok).toString();
if (fileDisplayName.isEmpty() || !ok)
fileDisplayName = q->fileUrl().fileName();
if (fileDisplayName == R"(/)" && FileUtils::isGvfsFile(q->fileUrl()))
if (fileDisplayName == R"(/)" && ProtocolUtils::isRemoteFile(q->fileUrl()))
fileDisplayName = this->attribute(DFileInfo::AttributeID::kIdFilesystem).toString();

return fileDisplayName;
Expand Down Expand Up @@ -890,7 +891,7 @@ bool AsyncFileInfoPrivate::isExecutable() const
if (!success) {
qCDebug(logDFMBase) << "cannot obtain the property kAccessCanExecute of" << q->fileUrl();

if (FileUtils::isGvfsFile(q->fileUrl())) {
if (ProtocolUtils::isRemoteFile(q->fileUrl())) {
qCDebug(logDFMBase) << "trying to get isExecutable by judging whether the dir can be iterated" << q->fileUrl();
struct dirent *next { nullptr };
DIR *dirp = opendir(filePath().toUtf8().constData());
Expand Down Expand Up @@ -1104,7 +1105,7 @@ int AsyncFileInfoPrivate::cacheAllAttributes(const QString &attributes)
auto symlink = symLinkTarget();
if (attribute(DFileInfo::AttributeID::kStandardIsSymlink).toBool()
&& !symlink.isEmpty()
&& !FileUtils::isLocalDevice(QUrl::fromLocalFile(symlink))) {
&& !ProtocolUtils::isLocalFile(QUrl::fromLocalFile(symlink))) {
FileInfoPointer info = InfoFactory::create<FileInfo>(QUrl::fromLocalFile(symlink));
auto asyncInfo = info.dynamicCast<AsyncFileInfo>();
if (asyncInfo) {
Expand Down
9 changes: 5 additions & 4 deletions src/dfm-base/file/local/localdiriterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <dfm-base/base/schemefactory.h>
#include <dfm-base/utils/fileutils.h>
#include <dfm-base/base/configs/dconfig/dconfigmanager.h>
#include <dfm-base/utils/protocolutils.h>

#include <dfm-io/denumerator.h>
#include <dfm-io/dfmio_utils.h>
Expand Down Expand Up @@ -62,7 +63,7 @@ FileInfoPointer LocalDirIteratorPrivate::fileInfo(const QSharedPointer<DFileInfo
}

auto targetPath = dfmInfo->attribute(dfmio::DFileInfo::AttributeID::kStandardSymlinkTarget).toString();
if (FileUtils::isLocalDevice(url) && (targetPath.isEmpty() || FileUtils::isLocalDevice(QUrl::fromLocalFile(targetPath)))) {
if (ProtocolUtils::isLocalFile(url) && (targetPath.isEmpty() || ProtocolUtils::isLocalFile(QUrl::fromLocalFile(targetPath)))) {
info = QSharedPointer<SyncFileInfo>(new SyncFileInfo(url));
} else {
info = QSharedPointer<AsyncFileInfo>(new AsyncFileInfo(url, dfmInfo));
Expand All @@ -72,7 +73,7 @@ FileInfoPointer LocalDirIteratorPrivate::fileInfo(const QSharedPointer<DFileInfo

if (info) {
if (!q->property("QueryAttributes").toString().isEmpty()
&& q->property("QueryAttributes").toString() != "*") {
&& q->property("QueryAttributes").toString() != "*") {
info->setExtendedAttributes(ExtInfoType::kFileNeedUpdate, true);
info->setExtendedAttributes(ExtInfoType::kFileNeedTransInfo, true);
}
Expand Down Expand Up @@ -212,7 +213,7 @@ void LocalDirIterator::cacheBlockIOAttribute()
const QUrl &rootUrl = this->url();
const QUrl &url = DFMIO::DFMUtils::buildFilePath(rootUrl.toString().toStdString().c_str(), ".hidden", nullptr);
d->hideFileList = DFMIO::DFMUtils::hideListFromUrl(url);
d->isLocalDevice = FileUtils::isLocalDevice(rootUrl);
d->isLocalDevice = ProtocolUtils::isLocalFile(rootUrl);
d->isCdRomDevice = FileUtils::isCdRomDevice(rootUrl);
}

Expand Down Expand Up @@ -266,7 +267,7 @@ bool LocalDirIterator::oneByOne()
if (info)
return !info->extendAttributes(ExtInfoType::kFileLocalDevice).toBool() || !d->dfmioDirIterator;

return !FileUtils::isLocalDevice(url()) || !d->dfmioDirIterator;
return !ProtocolUtils::isLocalFile(url()) || !d->dfmioDirIterator;
}

bool LocalDirIterator::initIterator()
Expand Down
Loading
Loading