mdx normal index check logic

This commit is contained in:
Xiao YiFang 2022-10-02 21:52:11 +08:00
parent 5a8de1ea1d
commit 4ab26f687c
3 changed files with 55 additions and 3 deletions

View file

@ -579,14 +579,63 @@ bool needToRebuildIndex( vector< string > const & dictionaryFiles,
return fileInfo.lastModified().toSecsSinceEpoch() < lastModified;
#else
QDir d(FsEncoding::decode( indexFile.c_str() ));
if(!d.exists()){
QFileInfo fileInfo( FsEncoding::decode( indexFile.c_str() ) );
if ( fileInfo.exists()&&fileInfo.isFile() )
{
QFile::remove(FsEncoding::decode( indexFile.c_str() ));
return true;
}
return false;
#endif
}
bool needToRebuildBTreeIndex( vector< string > const & dictionaryFiles,
string const & indexFile ) noexcept
{
unsigned long lastModified = 0;
for( std::vector< string >::const_iterator i = dictionaryFiles.begin();
i != dictionaryFiles.end(); ++i )
{
QString name = FsEncoding::decode( i->c_str() );
QFileInfo fileInfo( name );
unsigned long ts;
if( fileInfo.isDir() )
continue;
if( name.toLower().endsWith( ".zip" ) )
{
ZipFile::SplitZipFile zf( name );
if( !zf.exists() )
return true;
ts = zf.lastModified().toSecsSinceEpoch();
}
else
{
if ( !fileInfo.exists() )
return true;
ts = fileInfo.lastModified().toSecsSinceEpoch();
}
if ( ts > lastModified )
lastModified = ts;
}
QDir d(FsEncoding::decode( indexFile.c_str() ));
if(d.exists()){
d.removeRecursively();
}
QFileInfo fileInfo( FsEncoding::decode( indexFile.c_str() ) );
if ( !fileInfo.exists() )
return true;
return fileInfo.lastModified().toSecsSinceEpoch() < lastModified;
}
QString generateRandomDictionaryId()
{
return QString(

View file

@ -483,6 +483,9 @@ string makeDictionaryId( vector< string > const & dictionaryFiles ) noexcept;
bool needToRebuildIndex( vector< string > const & dictionaryFiles,
string const & indexFile ) noexcept;
bool needToRebuildBTreeIndex( vector< string > const & dictionaryFiles,
string const & indexFile ) noexcept;
/// Returns a random dictionary id useful for interactively created
/// dictionaries.
QString generateRandomDictionaryId();

2
mdx.cc
View file

@ -1401,7 +1401,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
string dictId = Dictionary::makeDictionaryId( dictFiles );
string indexFile = indicesDir + dictId;
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) ||
if ( Dictionary::needToRebuildBTreeIndex( dictFiles, indexFile ) ||
indexIsOldOrBad( dictFiles, indexFile ) )
{
// Building the index