mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-08-03 20:56:49 -04:00
Better handling of renamed files in monitored directory
When a file in the monitored directory is renamed, it is better to remove the old file from the library before adding the new one. Doing it the other way around will not work correctly - adding the new file will fail since a book with that UUID is already present in the library, and then that book will be removed!
This commit is contained in:
parent
58e8f71dda
commit
d0f7599cf6
@ -878,6 +878,12 @@ void ContentManager::updateLibraryFromDir(QString monitorDir)
|
||||
const auto kiwixLib = mp_library->getKiwixLibrary();
|
||||
kiwix::Manager manager(kiwixLib);
|
||||
bool needsRefresh = !removedZims.empty();
|
||||
for (auto bookPath : removedZims) {
|
||||
try {
|
||||
const auto book = kiwixLib->getBookByPath(bookPath.toStdString());
|
||||
mp_library->removeBookFromLibraryById(QString::fromStdString(book.getId()));
|
||||
} catch (...) {}
|
||||
}
|
||||
for (auto bookPath : addedZims) {
|
||||
if ( mp_library->isBeingDownloadedByUs(bookPath) ) {
|
||||
// qDebug() << "DBG: ContentManager::updateLibraryFromDir(): "
|
||||
@ -887,12 +893,6 @@ void ContentManager::updateLibraryFromDir(QString monitorDir)
|
||||
needsRefresh |= manager.addBookFromPath(bookPath.toStdString());
|
||||
}
|
||||
}
|
||||
for (auto bookPath : removedZims) {
|
||||
try {
|
||||
const auto book = kiwixLib->getBookByPath(bookPath.toStdString());
|
||||
mp_library->removeBookFromLibraryById(QString::fromStdString(book.getId()));
|
||||
} catch (...) {}
|
||||
}
|
||||
if (needsRefresh) {
|
||||
emit(booksChanged());
|
||||
setMonitorDirZims(monitorDir, newDirEntries);
|
||||
|
Loading…
x
Reference in New Issue
Block a user