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

getMediaCount does not fail if M/Counter is missing. #827

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,19 @@ namespace zim

entry_index_type Archive::getMediaCount() const
{
return countMimeType(
getMetadata("Counter"),
[](const std::string& mimetype) {
return mimetype.find("image/") == 0 ||
mimetype.find("video/") == 0 ||
mimetype.find("audio/") == 0;
}
);
try {
return countMimeType(
getMetadata("Counter"),
[](const std::string& mimetype) {
return mimetype.find("image/") == 0 ||
mimetype.find("video/") == 0 ||
mimetype.find("audio/") == 0;
}
);
} catch(const EntryNotFound& e) {
return (m_impl->getNamespaceEntryCount('I').v
+ m_impl->getNamespaceEntryCount('J').v);
}
kelson42 marked this conversation as resolved.
Show resolved Hide resolved
}

Uuid Archive::getUuid() const
Expand Down
4 changes: 4 additions & 0 deletions src/dirent_lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ entry_index_t getNamespaceBeginOffset(TDirentAccessor& direntAccessor, char ch)
ASSERT(ch, >=, 32);
ASSERT(ch, <=, 127);

if (direntAccessor.getDirentCount().v == 0) {
return entry_index_t(0);
}

entry_index_type lower = 0;
entry_index_type upper = entry_index_type(direntAccessor.getDirentCount());
auto d = direntAccessor.getDirent(entry_index_t(0));
Expand Down
3 changes: 3 additions & 0 deletions test/archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ TEST(ZimArchive, openingAnEmptyZimArchiveSucceeds)

zim::Archive archive(tmpfile->path());
ASSERT_TRUE(archive.check());

ASSERT_EQ(archive.getMediaCount(), 0);
ASSERT_EQ(archive.getArticleCount(), 0);
}

bool isNastyOffset(int offset) {
Expand Down
Loading