fix(dirWatcher):subVolume has not been excluded while adding '/' to search path.

This commit is contained in:
JunjieBai 2024-04-11 20:47:40 +08:00 committed by iaom
parent 63ec090747
commit 2f3d2cefad
2 changed files with 40 additions and 20 deletions

View File

@ -107,26 +107,7 @@ QStringList SearchDir::blackListOfDir(const QString &dirPath)
}
}
for (const Volume &volume : VolumeManager::self()->volumesHaveSubVolumes()) {
for (const QString &duplicateMountPoint : volume.mountPoints()) {
QMap<QString, QString> 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<QString, QString> 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;
}

View File

@ -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;