Directory monitoring ignores unchanged bad ZIMs

When a change to a monitored directory is detected, any bad ZIM files
in it (that could not be added to the library during the previous
update) are ignored unless their modification timestamp has changed.
This commit is contained in:
Veloman Yunkan 2024-08-25 15:53:49 +04:00 committed by Kelson
parent 3dd58b3ae4
commit fdac248492
2 changed files with 34 additions and 8 deletions

View File

@ -927,7 +927,8 @@ const char* monitoredDirZimFileHandlingMsgs[] = {
"", "",
"it is being downloaded by us, ignoring...", "it is being downloaded by us, ignoring...",
"the file was added to the library", "the file was added to the library",
"the file could not be added to the library" "the file could not be added to the library",
"it is an unchanged known bad zim file"
}; };
#endif #endif
@ -942,14 +943,32 @@ bool ContentManager::handleZimFileInMonitoredDirLogged(QString dir, QString file
return status == MonitoredZimFileInfo::ADDED_TO_THE_LIBRARY; return status == MonitoredZimFileInfo::ADDED_TO_THE_LIBRARY;
} }
void ContentManager::MonitoredZimFileInfo::updateStatus(const MonitoredZimFileInfo& prevInfo)
{
Q_ASSERT(prevInfo.status != ADDED_TO_THE_LIBRARY);
if ( this->lastModified == prevInfo.lastModified ) {
this->status = UNCHANGED_KNOWN_BAD_ZIM_FILE;
} else {
this->status = PROCESS_NOW;
}
}
ContentManager::MonitoredZimFileInfo ContentManager::getMonitoredZimFileInfo(QString dir, QString fileName) const ContentManager::MonitoredZimFileInfo ContentManager::getMonitoredZimFileInfo(QString dir, QString fileName) const
{ {
Q_UNUSED(dir); const auto bookPath = QDir::toNativeSeparators(dir + "/" + fileName);
Q_UNUSED(fileName);
// TODO: implement properly MonitoredZimFileInfo zimFileInfo;
MonitoredZimFileInfo zfi;
zfi.status = MonitoredZimFileInfo::PROCESS_NOW; zimFileInfo.lastModified = QFileInfo(bookPath).lastModified();
return zfi;
const auto& zimsInDir = m_knownZimsInDir[dir];
const auto fileInfoEntry = zimsInDir.constFind(fileName);
if ( fileInfoEntry != zimsInDir.constEnd() ) {
zimFileInfo.updateStatus(fileInfoEntry.value());
}
return zimFileInfo;
} }
int ContentManager::handleZimFileInMonitoredDir(QString dir, QString fileName) int ContentManager::handleZimFileInMonitoredDir(QString dir, QString fileName)

View File

@ -123,10 +123,17 @@ private: // types
ADDED_TO_THE_LIBRARY, ADDED_TO_THE_LIBRARY,
// the attempt to add the file to the library failed // the attempt to add the file to the library failed
COULD_NOT_BE_ADDED_TO_THE_LIBRARY COULD_NOT_BE_ADDED_TO_THE_LIBRARY,
// the file couldn't be added to the library earlier and hasn't
// changed since then
UNCHANGED_KNOWN_BAD_ZIM_FILE
}; };
void updateStatus(const MonitoredZimFileInfo& prevInfo);
ZimFileStatus status = PROCESS_NOW; ZimFileStatus status = PROCESS_NOW;
QDateTime lastModified;
}; };
typedef QMap<QString, MonitoredZimFileInfo> ZimFileName2InfoMap; typedef QMap<QString, MonitoredZimFileInfo> ZimFileName2InfoMap;