Skip to content

Commit

Permalink
Merge pull request #827 from openzim/fallback_no_counter
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr authored Oct 17, 2023
2 parents bd8f79c + 167be70 commit 6460196
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
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);
}
}

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

0 comments on commit 6460196

Please sign in to comment.