Skip to content

Commit

Permalink
Directory monitoring ignores unchanged bad ZIMs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
veloman-yunkan authored and kelson42 committed Sep 7, 2024
1 parent 3dd58b3 commit fdac248
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
33 changes: 26 additions & 7 deletions src/contentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion src/contentmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,17 @@ public slots:
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;
Expand Down

0 comments on commit fdac248

Please sign in to comment.