mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 11:37:56 -04:00
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:
parent
3dd58b3ae4
commit
fdac248492
@ -927,7 +927,8 @@ const char* monitoredDirZimFileHandlingMsgs[] = {
|
||||
"",
|
||||
"it is being downloaded by us, ignoring...",
|
||||
"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
|
||||
@ -942,14 +943,32 @@ bool ContentManager::handleZimFileInMonitoredDirLogged(QString dir, QString file
|
||||
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
|
||||
{
|
||||
Q_UNUSED(dir);
|
||||
Q_UNUSED(fileName);
|
||||
// TODO: implement properly
|
||||
MonitoredZimFileInfo zfi;
|
||||
zfi.status = MonitoredZimFileInfo::PROCESS_NOW;
|
||||
return zfi;
|
||||
const auto bookPath = QDir::toNativeSeparators(dir + "/" + fileName);
|
||||
|
||||
MonitoredZimFileInfo zimFileInfo;
|
||||
|
||||
zimFileInfo.lastModified = QFileInfo(bookPath).lastModified();
|
||||
|
||||
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)
|
||||
|
@ -123,10 +123,17 @@ private: // types
|
||||
ADDED_TO_THE_LIBRARY,
|
||||
|
||||
// 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;
|
||||
QDateTime lastModified;
|
||||
};
|
||||
|
||||
typedef QMap<QString, MonitoredZimFileInfo> ZimFileName2InfoMap;
|
||||
|
Loading…
x
Reference in New Issue
Block a user