Skip to content

Commit

Permalink
fix: soundDir index not updating when sounds modified (#1427)
Browse files Browse the repository at this point in the history
  • Loading branch information
shenlebantongying authored Mar 20, 2024
1 parent 68ed2da commit e8f3a94
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/dict/sounddir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <set>
#include <QDir>
#include <QFileInfo>
#include <QDirIterator>

namespace SoundDir {

Expand Down Expand Up @@ -438,7 +439,24 @@ vector< sptr< Dictionary::Class > > makeDictionaries( Config::SoundDirs const &

string indexFile = indicesDir + dictId;

if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) {
// Check if the soundDir and its subdirs' modification date changed, that means the user modified the sound files inside

bool soundDirModified = false;
{
QDateTime indexFileModifyTime = QFileInfo( QString::fromStdString( indexFile ) ).lastModified();
QDirIterator it( dir.path(),
QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks,
QDirIterator::Subdirectories );
while ( it.hasNext() ) {
it.next();
if ( it.fileInfo().lastModified() > indexFileModifyTime ) {
soundDirModified = true;
break;
}
}
}

if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) || soundDirModified ) {
// Building the index

qDebug() << "Sounds: Building the index for directory: " << soundDir.path;
Expand Down

0 comments on commit e8f3a94

Please sign in to comment.