Optimize the handle of subvolume while add index dir.
This commit is contained in:
parent
2760b30a2a
commit
91b455341d
|
@ -434,24 +434,82 @@ int DirWatcher::appendIndexableListItem(const QString &path)
|
|||
}
|
||||
}
|
||||
|
||||
//处理自动挂载子卷下的目录,目前方案将其合并为一个,只保留了mountpoint下的目录
|
||||
//处理自动挂载子卷下的目录
|
||||
for (auto t = m_infoOfSubvolume.constBegin(); t != m_infoOfSubvolume.constEnd(); t++) {
|
||||
QString mountPoint = t.value();
|
||||
QString spec = t.key();
|
||||
QString tmp = path;
|
||||
|
||||
//要添加目录下存在子卷(要添加/data,但挂到/home的/data/home是子卷),若添加了/home则将/data/home排除
|
||||
if (spec.startsWith(path + "/")) {
|
||||
blackList << spec;
|
||||
for (QString &indexDir : m_indexableDirList) {
|
||||
if (indexDir == mountPoint || mountPoint.startsWith(indexDir + "/")) {
|
||||
blackList << spec;
|
||||
}
|
||||
if (indexDir.startsWith(mountPoint + "/")) {
|
||||
blackList << indexDir.replace(0, mountPoint.length(), spec);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//要添加目录下存在子卷挂载点,同上
|
||||
if (mountPoint.startsWith(path + "/")) {
|
||||
|
||||
for (QString &indexDir : m_indexableDirList) {
|
||||
if (indexDir == spec || spec.startsWith(indexDir + "/")) {
|
||||
blackList << mountPoint;
|
||||
}
|
||||
if (indexDir.startsWith(spec + "/")) {
|
||||
blackList << indexDir.replace(0, spec.length(), mountPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (path.startsWith(spec + "/") or path == spec) {
|
||||
tmp.replace(0, spec.length(), mountPoint);
|
||||
if (this->handleIndexItemAppend(tmp, blackList)) {
|
||||
qDebug() << QString("The path:%1 has been replaced into %2").arg(path, tmp);
|
||||
} else {
|
||||
resultCode = -1;
|
||||
//要添加的目录是子卷或在子卷下(/data/home or /data/home/xxx)
|
||||
if (path.startsWith(spec + "/") || path == spec) {
|
||||
for (QString &indexDir : m_indexableDirList) {
|
||||
//已添加挂载点或其上层目录
|
||||
if (mountPoint.startsWith(indexDir + "/") || indexDir == mountPoint) {
|
||||
qCritical() << "Fail to add" << path << "The mount point or its father:" << indexDir << "has been added";
|
||||
resultCode = -3;
|
||||
return resultCode;
|
||||
}
|
||||
//已添加挂载点下其他目录
|
||||
if (indexDir.startsWith(mountPoint + "/")) {
|
||||
|
||||
QString tmp = indexDir;
|
||||
tmp.replace(0, mountPoint.length(), spec);
|
||||
if (tmp == path) {
|
||||
qCritical() << "Fail to add" << path << "The same path which is in the subvolume has been added.";
|
||||
resultCode = -4;
|
||||
return resultCode;
|
||||
} else if (tmp.startsWith(path + "/")) {//已添加的子卷子目录替换前缀后在要添加目录下
|
||||
blackList << tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//要添加的目录是挂载点或在挂载点下(/home or /home/xxx)
|
||||
if (path.startsWith(mountPoint + "/") || path == mountPoint) {
|
||||
for (QString &indexDir : m_indexableDirList) {
|
||||
//已添加子卷或其上层目录
|
||||
if (spec.startsWith(indexDir + "/") || indexDir == spec) {
|
||||
qCritical() << "Fail to add" << path << "The subvolume or its father:" << indexDir << "has been added";
|
||||
resultCode = -3;
|
||||
return resultCode;
|
||||
}
|
||||
//已添加子卷下其他目录
|
||||
if (indexDir.startsWith(spec + "/")) {
|
||||
QString tmp = indexDir;
|
||||
tmp.replace(0, spec.length(), mountPoint);
|
||||
if (tmp == path) {
|
||||
qCritical() << "Fail to add" << path << "The same path which is in the mount point has been added.";
|
||||
resultCode = -4;
|
||||
return resultCode;
|
||||
} else if (tmp.startsWith(path + "/")) {//已添加的子卷子目录替换前缀后在要添加目录下
|
||||
blackList << tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue