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