Merge branch '0621-dev' into 'dev-unity'
[Fix] Path inclusive relation judgment incorrectly. See merge request kylin-desktop/ukui-search!55
This commit is contained in:
commit
73b72167c4
|
@ -178,6 +178,22 @@ QString FileUtils::getSettingName(const QString& setting) {
|
|||
return setting.right(setting.length() - setting.lastIndexOf("/") - 1);
|
||||
}
|
||||
|
||||
bool FileUtils::isOrUnder(QString pathA, QString pathB)
|
||||
{
|
||||
if(pathA[0] != "/")
|
||||
pathA.prepend("/");
|
||||
if(pathB[0] != "/")
|
||||
pathB.prepend("/");
|
||||
|
||||
if(pathA.length() < pathB.length())
|
||||
return false;
|
||||
|
||||
if(pathA == pathB || pathA.startsWith(pathB + "/"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void FileUtils::loadHanziTable(const QString &fileName) {
|
||||
QFile file(fileName);
|
||||
|
|
|
@ -67,6 +67,8 @@ public:
|
|||
static QString getFileName(const QString &);
|
||||
static QString getAppName(const QString &);
|
||||
static QString getSettingName(const QString &);
|
||||
//A is or under B
|
||||
static bool isOrUnder(QString pathA, QString pathB);
|
||||
|
||||
//chinese character to pinyin
|
||||
static QMap<QString, QStringList> map_chinese2pinyin;
|
||||
|
|
|
@ -155,15 +155,19 @@ bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool rem
|
|||
//why QSetting's key can't start with "/"??
|
||||
QString pathKey = path.right(path.length() - 1);
|
||||
|
||||
if (pathKey.endsWith(QLatin1Char('/'))) {
|
||||
pathKey = pathKey.mid(0, pathKey.length() - 1);
|
||||
}
|
||||
|
||||
QStringList blockDirs = m_block_dirs_settings->allKeys();
|
||||
for(QString i : blockDirs) {
|
||||
if(pathKey.startsWith(i)) {
|
||||
if(FileUtils::isOrUnder(pathKey, i)) {
|
||||
// returnCode = QString(tr("My parent folder has been blocked!"));
|
||||
returnCode = PATH_PARENT_BLOCKED;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(i.startsWith(pathKey))
|
||||
if(FileUtils::isOrUnder(i, pathKey))
|
||||
m_block_dirs_settings->remove(i);
|
||||
}
|
||||
m_block_dirs_settings->setValue(pathKey, "0");
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <QDBusInterface>
|
||||
#include <QApplication>
|
||||
#include "libsearch_global.h"
|
||||
#include "file-utils.h"
|
||||
|
||||
#define CONTROL_CENTER_PERSONALISE_GSETTINGS_ID "org.ukui.control-center.personalise"
|
||||
#define TRANSPARENCY_KEY "transparency"
|
||||
|
|
|
@ -49,7 +49,7 @@ bool InotifyWatch::removeWatch(const QString &path, bool removeFromDatabase)
|
|||
for(QMap<int, QString>::Iterator i = currentPath.begin(); i != currentPath.end();) {
|
||||
// qDebug() << i.value();
|
||||
// if(i.value().length() > path.length()) {
|
||||
if(i.value().startsWith(path)) {
|
||||
if(FileUtils::isOrUnder(i.value(), path)) {
|
||||
qDebug() << "remove path: " << i.value();
|
||||
inotify_rm_watch(m_inotifyFd, currentPath.key(path));
|
||||
PendingFile f(i.value());
|
||||
|
@ -65,7 +65,8 @@ bool InotifyWatch::removeWatch(const QString &path, bool removeFromDatabase)
|
|||
for(QMap<int, QString>::Iterator i = currentPath.begin(); i != currentPath.end();) {
|
||||
// qDebug() << i.value();
|
||||
if(i.value().length() > path.length()) {
|
||||
if(i.value().startsWith(path)) {
|
||||
if(FileUtils::isOrUnder(i.value(), path)) {
|
||||
// if(i.value().startsWith(path + "/")) {
|
||||
// qDebug() << "remove path: " << i.value();
|
||||
inotify_rm_watch(m_inotifyFd, currentPath.key(path));
|
||||
currentPath.erase(i++);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*
|
||||
*/
|
||||
#include "pending-file-queue.h"
|
||||
#include "file-utils.h"
|
||||
#include <malloc.h>
|
||||
using namespace Zeeker;
|
||||
static PendingFileQueue *global_instance_pending_file_queue = nullptr;
|
||||
|
@ -88,7 +89,7 @@ void PendingFileQueue::enqueue(const PendingFile &file)
|
|||
// Because our datebase need to delete those indexs one by one.
|
||||
if(file.shouldRemoveIndex() && file.isDir()) {
|
||||
const auto keepFile = [&file](const PendingFile& pending) {
|
||||
return (!pending.path().startsWith(file.path()) || pending.shouldRemoveIndex());
|
||||
return (!FileUtils::isOrUnder(pending.path(), file.path()) || pending.shouldRemoveIndex());
|
||||
};
|
||||
const auto end = m_cache.end();
|
||||
const auto droppedFilesBegin = std::stable_partition(m_cache.begin(), end, keepFile);
|
||||
|
|
|
@ -81,7 +81,7 @@ void SearchManager::onKeywordSearch(QString keyword, QQueue<QString> *searchResu
|
|||
bool SearchManager::isBlocked(QString &path) {
|
||||
QStringList blockList = GlobalSettings::getInstance()->getBlockDirs();
|
||||
for(QString i : blockList) {
|
||||
if(path.startsWith(i.prepend("/")))
|
||||
if(FileUtils::isOrUnder(path, i))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -414,7 +414,7 @@ void DirectSearch::run() {
|
|||
|
||||
bool findIndex = false;
|
||||
for (QString j : blockList) {
|
||||
if (i.absoluteFilePath().startsWith(j.prepend("/"))) {
|
||||
if (FileUtils::isOrUnder(i.absoluteFilePath(), j)) {
|
||||
findIndex = true;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue