Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for fileName in eraseBookFilesFromComputer #816

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/contentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,12 @@ QString ContentManager::downloadBook(const QString &id)
return QString::fromStdString(download->getDid());
}

void ContentManager::eraseBookFilesFromComputer(const QString dirPath, const QString filename)
void ContentManager::eraseBookFilesFromComputer(const QString dirPath, const QString fileName)
{
QDir dir(dirPath, filename);
if (fileName == "*") {
return;
}
QDir dir(dirPath, fileName);
for(const QString& file: dir.entryList()) {
dir.remove(file);
}
Expand All @@ -272,8 +275,8 @@ void ContentManager::eraseBook(const QString& id)
tabBar->closeTabsByZimId(id);
kiwix::Book book = mp_library->getBookById(id);
QString dirPath = QString::fromStdString(kiwix::removeLastPathElement(book.getPath()));
QString filename = QString::fromStdString(kiwix::getLastPathElement(book.getPath())) + "*";
eraseBookFilesFromComputer(dirPath, filename);
Comment on lines 277 to -276
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is probably to eraseBookFilesFromComputer to split the bookPath and erase book properly.

The signature of the method should probably be:
bool eraseBookFilesFromComputer(const Book& book)

QString fileName = QString::fromStdString(kiwix::getLastPathElement(book.getPath())) + "*";
eraseBookFilesFromComputer(dirPath, fileName);
mp_library->removeBookFromLibraryById(id);
mp_library->save();
emit mp_library->bookmarksChanged();
Expand Down