Skip to content

Commit

Permalink
Fix iterByTitle.
Browse files Browse the repository at this point in the history
If we have a specific title index, we must iterate on it.
We must not iterate on a (wrong) subset of the entries.

Related to #514
  • Loading branch information
mgautierfr committed Mar 30, 2021
1 parent d4801b6 commit acac284
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,14 @@ namespace zim

Archive::EntryRange<EntryOrder::titleOrder> Archive::iterByTitle() const
{
return EntryRange<EntryOrder::titleOrder>(m_impl, m_impl->getStartUserEntry().v, m_impl->getEndUserEntry().v);
if (m_impl->hasFullTitleIndex()) {
// We don't have an index listing only front entry. We have to loop over user entry.
// (`C` namespace in new zim scheme, all namespace in old ones)
return EntryRange<EntryOrder::titleOrder>(m_impl, m_impl->getStartUserEntry().v, m_impl->getEndUserEntry().v);
} else {
// We have an index. We can "simply" loop over all front entries.
return EntryRange<EntryOrder::titleOrder>(m_impl, 0, m_impl->getFrontEntryCount().v);
}
}

Archive::EntryRange<EntryOrder::efficientOrder> Archive::iterEfficient() const
Expand Down
2 changes: 2 additions & 0 deletions src/fileimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ makeFileReader(std::shared_ptr<const FileCompound> zimFile, offset_t offset, zsi
direntReader(new DirentReader(zimReader)),
clusterCache(envValue("ZIM_CLUSTERCACHE", CLUSTER_CACHE_SIZE)),
m_newNamespaceScheme(false),
m_hasFullTitleIndex(false),
m_startUserEntry(0),
m_endUserEntry(0)
{
Expand Down Expand Up @@ -150,6 +151,7 @@ makeFileReader(std::shared_ptr<const FileCompound> zimFile, offset_t offset, zsi
offset_t titleOffset(header.getTitleIdxPos());
zsize_t titleSize(sizeof(entry_index_type)*header.getArticleCount());
mp_titleDirentAccessor = getTitleAccessor(titleOffset, titleSize, "Title index table");
const_cast<bool&>(m_hasFullTitleIndex) = true;
}

readMimeTypes();
Expand Down
2 changes: 2 additions & 0 deletions src/fileimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace zim
ConcurrentCache<cluster_index_type, ClusterHandle> clusterCache;

const bool m_newNamespaceScheme;
const bool m_hasFullTitleIndex;
const entry_index_t m_startUserEntry;
const entry_index_t m_endUserEntry;

Expand Down Expand Up @@ -89,6 +90,7 @@ namespace zim
const Fileheader& getFileheader() const { return header; }
zsize_t getFilesize() const;
bool hasNewNamespaceScheme() const { return m_newNamespaceScheme; }
bool hasFullTitleIndex() const { return m_hasFullTitleIndex; }

FileCompound::PartRange getFileParts(offset_t offset, zsize_t size);
std::shared_ptr<const Dirent> getDirent(entry_index_t idx);
Expand Down

0 comments on commit acac284

Please sign in to comment.