From 2f3d2cefad1522d09a79ca7d9b1f8ebc924e20a2 Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Thu, 11 Apr 2024 20:47:40 +0800 Subject: [PATCH] fix(dirWatcher):subVolume has not been excluded while adding '/' to search path. --- .../dirwatcher/search-dir.cpp | 59 ++++++++++++------- .../dirwatcher/search-dir.h | 1 + 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/ukui-search-service-dir-manager/dirwatcher/search-dir.cpp b/ukui-search-service-dir-manager/dirwatcher/search-dir.cpp index bcaa323..a010655 100644 --- a/ukui-search-service-dir-manager/dirwatcher/search-dir.cpp +++ b/ukui-search-service-dir-manager/dirwatcher/search-dir.cpp @@ -107,26 +107,7 @@ QStringList SearchDir::blackListOfDir(const QString &dirPath) } } - for (const Volume &volume : VolumeManager::self()->volumesHaveSubVolumes()) { - for (const QString &duplicateMountPoint : volume.mountPoints()) { - QMap subVolumeInfo = volume.subVolumes(); - if (subVolumeInfo.keys().contains(duplicateMountPoint)) { - continue; - } - for (auto it = subVolumeInfo.constBegin(); it != subVolumeInfo.constEnd(); it++) { - QString spec = it.key(); - QString subMountPoint = duplicateMountPoint + it.value(); - //排除搜索列表指定多个目录时子卷会重复包含的情况,比如同时指定/home和/data/home - QString tmp = dirPath; - if (dirPath.startsWith(subMountPoint)) { - blackListOfDir.append(tmp.replace(0, subMountPoint.length(), spec)); - } - if (dirPath.startsWith(spec)) { - blackListOfDir.append(tmp.replace(0, spec.length(), subMountPoint)); - } - } - } - } + blackListOfDir << handleSubVolumes4SingleDir(dirPath); return blackListOfDir; } @@ -177,6 +158,7 @@ void SearchDir::handleBlackListGenerate() } m_blackList << repeatMountPoints; } + m_blackList.append(handleSubVolumes4SingleDir("/")); m_blackList.removeDuplicates(); return; } @@ -354,3 +336,40 @@ void SearchDir::handleBlackListGenerate() } m_blackList.removeDuplicates(); } + +QStringList SearchDir::handleSubVolumes4SingleDir(const QString &searchDir) { + QStringList blackList; + for (const Volume &volume : VolumeManager::self()->volumesHaveSubVolumes()) { + QMap subVolumeInfo = volume.subVolumes(); + for (auto it = subVolumeInfo.constBegin(); it != subVolumeInfo.constEnd(); it++) { + QString subMountPoint = it.key(); + + for (const QString &duplicateMountPoint : volume.mountPoints()) { + if (subVolumeInfo.keys().contains(duplicateMountPoint)) { + continue; + } + QString spec = duplicateMountPoint + it.value(); //子卷对应目录 + + if (searchDir == "/") { + blackList << spec; + } else { + //排除搜索列表指定多个目录时子卷会重复包含的情况,比如同时指定/home和/data/home + QString tmp = searchDir; + if (searchDir.startsWith(subMountPoint + "/")) { + blackList << tmp.replace(0, subMountPoint.length(), spec); + } + //要添加目录下存在子卷(要添加/data,但挂到/home的/data/home是子卷),若添加了/home则将/data/home排除 + if (searchDir.startsWith(spec + "/")) { + blackList << tmp.replace(0, spec.length(), subMountPoint); + } + if (spec.startsWith(searchDir + "/")) { + if (searchDir == subMountPoint || subMountPoint.startsWith(searchDir + "/")) { + blackList << spec; + } + } + } + } + } + } + return blackList; +} diff --git a/ukui-search-service-dir-manager/dirwatcher/search-dir.h b/ukui-search-service-dir-manager/dirwatcher/search-dir.h index 9af3171..aff0449 100644 --- a/ukui-search-service-dir-manager/dirwatcher/search-dir.h +++ b/ukui-search-service-dir-manager/dirwatcher/search-dir.h @@ -46,6 +46,7 @@ public: static QStringList blackListOfDir(const QString &dirPath); private: void handleBlackListGenerate(); + static QStringList handleSubVolumes4SingleDir(const QString& searchDir); QString m_path; QStringList m_blackList; ErrorInfo m_error = ErrorInfo::Successful;