From 7161db8e2ab4b4a56b93fee72aad1f97fdd11614 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 28 Nov 2021 20:55:09 +0400 Subject: [PATCH] Manager::reload() also removes books from Library --- include/manager.h | 4 ++++ src/manager.cpp | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/manager.h b/include/manager.h index 13fe19f10..3023a81a2 100644 --- a/include/manager.h +++ b/include/manager.h @@ -45,10 +45,12 @@ class LibraryManipulator bool addBookToLibrary(const Book& book); void addBookmarkToLibrary(const Bookmark& bookmark); + uint32_t removeBooksNotUpdatedSince(Library::Revision rev); protected: // overrides virtual void bookWasAddedToLibrary(const Book& book); virtual void bookmarkWasAddedToLibrary(const Bookmark& bookmark); + virtual void booksWereRemovedFromLibrary(); private: // data kiwix::Library& library; @@ -81,6 +83,8 @@ class Manager * Sync the contents of the library with one or more `library.xml` files. * * The metadata of the library files is trusted unconditionally. + * Any books not present in the input library.xml files are removed + * from the library. * * @param paths The (utf8) paths to the `library.xml` files. */ diff --git a/src/manager.cpp b/src/manager.cpp index b65353542..3f24fad17 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -63,6 +63,15 @@ void LibraryManipulator::addBookmarkToLibrary(const Bookmark& bookmark) bookmarkWasAddedToLibrary(bookmark); } +uint32_t LibraryManipulator::removeBooksNotUpdatedSince(Library::Revision rev) +{ + const auto n = library.removeBooksNotUpdatedSince(rev); + if ( n != 0 ) { + booksWereRemovedFromLibrary(); + } + return n; +} + void LibraryManipulator::bookWasAddedToLibrary(const Book& book) { } @@ -71,6 +80,10 @@ void LibraryManipulator::bookmarkWasAddedToLibrary(const Bookmark& bookmark) { } +void LibraryManipulator::booksWereRemovedFromLibrary() +{ +} + //////////////////////////////////////////////////////////////////////////////// // Manager //////////////////////////////////////////////////////////////////////////////// @@ -291,6 +304,7 @@ bool Manager::readBookmarkFile(const std::string& path) void Manager::reload(const Paths& paths) { + const auto libRevision = manipulator->getLibrary().getRevision(); for (std::string path : paths) { if (!path.empty()) { if ( kiwix::isRelativePath(path) ) @@ -301,6 +315,8 @@ void Manager::reload(const Paths& paths) } } } + + manipulator->removeBooksNotUpdatedSince(libRevision); } }