fix: add isMountedByGio to check GVfs mount status#313
Conversation
There was a problem hiding this comment.
Sorry @liyigang1, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: liyigang1 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
b27a6f6 to
dbda171
Compare
deepin pr auto review★ 总体评分:60分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 diff --git a/src/dfm-mount/private/dnetworkmounter.cpp b/src/dfm-mount/private/dnetworkmounter.cpp
index 6ad2fca..safe_mount 100644
--- a/src/dfm-mount/private/dnetworkmounter.cpp
+++ b/src/dfm-mount/private/dnetworkmounter.cpp
@@ -323,7 +323,7 @@ void DNetworkMounter::mountByDaemon(const QString &address, GetMountPassInfo get
QString mpt;
QString addr(QUrl::fromPercentEncoding(address.toLower().toLocal8Bit()));
- if (isMounted(addr, mpt) || isMountedByGio(address.toLower(), mpt)) {
+ if (isMounted(addr, mpt) || isMountedByGio(address, mpt)) {
if (mountResult)
mountResult(false, Utils::genOperateErrorInfo(DeviceError::kGIOErrorAlreadyMounted), mpt);
return;
@@ -691,15 +691,25 @@ bool DNetworkMounter::isMounted(const QString &address, QString &mpt)
return false;
}
}
+
+// Detect if the network URI is already mounted by GIO/GVFS to avoid duplicate mount errors
+bool DNetworkMounter::isMountedByGio(const QString &url, QString &mpt)
+{
+ GFile_autoptr file = g_file_new_for_uri(url.toStdString().c_str());
+ if (!file)
+ return false;
+
+ GError_autoptr error = nullptr;
+ GCancellable *cancellable = g_cancellable_new();
+ GMount_autoptr mount = g_file_find_enclosing_mount(file, cancellable, &error);
+ g_object_unref(cancellable);
+ if (!mount) {
+ QUrl parsedUrl(url);
+ QString safeUrl = QString("%1://%2%3").arg(parsedUrl.scheme(), parsedUrl.host(), parsedUrl.path());
+ qWarning() << "gio: cannot find enclosing mount for" << safeUrl << (error ? error->message : "");
+ return false;
+ }
+
+ // Prefer the default location (e.g., the mount's "home" directory)
+ GFile_autoptr defLocation = g_mount_get_default_location(mount);
+ if (defLocation) {
+ g_autofree char *path = g_file_get_path(defLocation);
+ if (path) {
+ mpt = QString::fromUtf8(path);
+ return true;
+ }
+ }
+
+ // Fallback to the mount root
+ GFile_autoptr root = g_mount_get_root(mount);
+ if (root) {
+ g_autofree char *path = g_file_get_path(root);
+ if (path) {
+ mpt = QString::fromUtf8(path);
+ return true;
+ }
+ }
+
+ return false;
+} |
Use std::string for directory path concatenation to avoid QString's normalization of UTF-8 BOM (U+FEFF / zero-width no-break space). 使用 std::string 进行路径拼接,避免 QString 对 UTF-8 BOM (零宽不换行空格) 的规范化导致字节丢失。 Log: 修复路径拼接时 BOM 字符丢失的问题 Bug: https://pms.uniontech.com//bug-view-367075.html Influence: 修复后包含 BOM/零宽不换行空格的路径能正确拼接,避免文件操作失败。
Add DNetworkMounter::isMountedByGio which uses GIO API to query whether a network URL is mounted via GVfs, returning the mount point. Also integrate the check in mountByDaemon to avoid duplicate mounting.
添加 isMountedByGio 函数,通过 GIO API 检查 GVfs 挂载状态,
并在 mountByDaemon 中集成该检查,避免重复挂载。
Log: 新增 isMountedByGio 函数检查 GVfs 挂载状态
Bug: https://pms.uniontech.com/bug-view-367163.html
Influence: 挂载网络设备时增加 GVfs 挂载检测,避免因 GVfs 已挂载导致重复挂载失败。