From efccb96c2c152d288adb9ac3ecd6a68caa1498b1 Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Fri, 18 Sep 2026 21:39:11 +0800 Subject: [PATCH] fix: replace %5C with backslash in trash URI for GIO compat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: QUrl::toString() percent-encodes backslashes to %5C, but GIO's trash backend uses raw backslashes internally, causing URI mismatch and "file not found" on delete and enumerate 2. Fix: in createGFile(), replace %5C back to raw backslash after toString(); route DEnumeratorPrivate::createEnumerator() through createGFile() instead of g_file_new_for_uri(url.toString()) 3. Impact: createGFile() branch and enumerator creation now consistent; originPath:: branch (g_file_new_for_path) unaffected; all createGFile() callers and enumerator paths benefit Log: fix trash files with backslash in filename cannot be deleted Influence: 1. Test deleting trash files with backslash in filename (e.g. .wechat\conf) 2. Test enumerating trash directory with backslash-named files 3. Test normal file operations (copy, move, delete, rename) with regular filenames 4. Test file operations with special characters in names fix: 修复含反斜杠文件名的回收站文件无法删除 1. 根因:QUrl::toString()将反斜杠编码为%5C,而GIO trash后端内部 使用原始反斜杠,导致URI不匹配,删除和枚举时报"找不到文件" 2. 方案:createGFile()中toString()后将%5C替换回原始反斜杠; DEnumeratorPrivate::createEnumerator()改用createGFile()而非 g_file_new_for_uri(url.toString()),统一所有URI转GFile路径 3. 影响:createGFile()分支与枚举器创建路径现在一致; originPath::分支(g_file_new_for_path)不受影响; 所有createGFile()调用方和枚举路径均受益 Log: 修复含反斜杠文件名的回收站文件无法删除的问题 Influence: 1. 测试删除文件名含反斜杠的回收站文件(如.wechat\conf) 2. 测试枚举含反斜杠文件名的回收站目录 3. 测试普通文件名(不含特殊字符)的文件操作(复制、移动、删除、重命名) 4. 测试含特殊字符文件名的文件操作 --- src/dfm-io/dfm-io/denumerator.cpp | 5 ++--- src/dfm-io/dfm-io/utils/dlocalhelper.cpp | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/dfm-io/dfm-io/denumerator.cpp b/src/dfm-io/dfm-io/denumerator.cpp index 6cbe4fa4..cfb96072 100644 --- a/src/dfm-io/dfm-io/denumerator.cpp +++ b/src/dfm-io/dfm-io/denumerator.cpp @@ -89,8 +89,7 @@ void DEnumeratorPrivate::clean() bool DEnumeratorPrivate::createEnumerator(const QUrl &url, QPointer me) { - const QString &uriPath = url.toString(); - g_autoptr(GFile) gfile = g_file_new_for_uri(uriPath.toLocal8Bit().data()); + g_autoptr(GFile) gfile = DLocalHelper::createGFile(url); g_autoptr(GError) gerror = nullptr; checkAndResetCancel(); @@ -116,7 +115,7 @@ bool DEnumeratorPrivate::createEnumerator(const QUrl &url, QPointermessage; + qWarning() << "create enumerator failed, url: " << url << " error: " << error.errorMsg() << gerror->message; } else { stackEnumerator.push_back(genumerator); } diff --git a/src/dfm-io/dfm-io/utils/dlocalhelper.cpp b/src/dfm-io/dfm-io/utils/dlocalhelper.cpp index 5cf0fd32..0898e571 100644 --- a/src/dfm-io/dfm-io/utils/dlocalhelper.cpp +++ b/src/dfm-io/dfm-io/utils/dlocalhelper.cpp @@ -1093,8 +1093,11 @@ GFile *DLocalHelper::createGFile(const QUrl &uri) QString path = uri.userInfo().isEmpty() || !uri.userInfo().startsWith("originPath::") ? QString() : uri.userInfo().replace("originPath::", ""); + QString uriStr = uri.toString(); + uriStr.replace("%5C", "\\"); + GFile *gfile = path.isEmpty() ? - g_file_new_for_uri(uri.toString().toLocal8Bit().data()) : + g_file_new_for_uri(uriStr.toLocal8Bit().data()) : g_file_new_for_path(path.toLatin1().data()); return gfile; }