From 1ad358bb84d2cecc0302e5553f7c882e8b13bb04 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Fri, 7 Oct 2022 17:08:10 +0800 Subject: [PATCH] xapian remove obsolete ftx index --- goldendict.pro | 1 + loaddictionaries.cc | 27 ++++++++++++++++----------- utils.cc | 7 +++++++ utils.hh | 6 ++++++ 4 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 utils.cc diff --git a/goldendict.pro b/goldendict.pro index e3cafde7..a24facaf 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -428,6 +428,7 @@ SOURCES += folding.cc \ btreeidx.cc \ stardict.cc \ chunkedstorage.cc \ + utils.cc \ weburlrequestinterceptor.cpp \ xdxf2html.cc \ iconv.cc \ diff --git a/loaddictionaries.cc b/loaddictionaries.cc index 38c88a1f..c3ec702c 100644 --- a/loaddictionaries.cc +++ b/loaddictionaries.cc @@ -397,19 +397,24 @@ void loadDictionaries( QWidget * parent, bool showInitially, QDir indexDir( Config::getIndexDir() ); - QStringList allIdxFiles = indexDir.entryList( QDir::Files ); + QStringList allIdxFiles = indexDir.entryList( QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks ); - for( QStringList::const_iterator i = allIdxFiles.constBegin(); - i != allIdxFiles.constEnd(); ++i ) + for( QStringList::const_iterator i = allIdxFiles.constBegin(); i != allIdxFiles.constEnd(); ++i ) { - if ( ids.find( FsEncoding::encode( *i ) ) == ids.end() - && i->size() == 32 ) - indexDir.remove( *i ); - else - if ( i->endsWith( "_FTS" ) - && i->size() == 36 - && ids.find( FsEncoding::encode( i->left( 32 ) ) ) == ids.end() ) - indexDir.remove( *i ); + if( i->size() >= 32 && ids.find( FsEncoding::encode( i->left( 32 ) ) ) == ids.end() ) + { + if( QFile::exists( *i ) ) + { + indexDir.remove( *i ); + } + else + { + // must be folder . + auto dirPath = Utils::Path::combine( Config::getIndexDir(), *i ); + QDir t( dirPath ); + t.removeRecursively(); + } + } } // Run deferred inits diff --git a/utils.cc b/utils.cc new file mode 100644 index 00000000..928becee --- /dev/null +++ b/utils.cc @@ -0,0 +1,7 @@ +#include "utils.hh" +#include + +QString Utils::Path::combine(const QString& path1, const QString& path2) +{ + return QDir::cleanPath(path1 + QDir::separator() + path2); +} diff --git a/utils.hh b/utils.hh index ff27321e..e8cf5fe8 100644 --- a/utils.hh +++ b/utils.hh @@ -274,6 +274,10 @@ inline bool isAudioUrl( QUrl const & url ) } +namespace Path{ +QString combine(const QString& path1, const QString& path2); +} + } namespace @@ -313,4 +317,6 @@ inline QString getHostBaseFromUrl( QUrl const & url ) } } + + #endif // UTILS_HH