From e821e9199dd70867d2d7a7d79e09595ea144f58c Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 8 Dec 2023 16:58:10 +0100 Subject: [PATCH] Bump minor version and add new api to get if archive has alias. Fix #844 --- include/zim/archive.h | 14 ++++++++++++++ src/archive.cpp | 5 +++++ src/fileheader.cpp | 2 +- src/fileimpl.cpp | 4 ++++ src/fileimpl.h | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/zim/archive.h b/include/zim/archive.h index 7539b96c6..bf33012c2 100644 --- a/include/zim/archive.h +++ b/include/zim/archive.h @@ -462,6 +462,20 @@ namespace zim */ bool hasNewNamespaceScheme() const; + /** Get if the zim archive may have alias entries. + * + * Alias entries are entries (two at least) pointing to the same + * content (same cluster/blob id). + * + * This method is just a hint. + * If true, its means that zim archive has been created with a implementation + * allowing alias creation. + * If false, it means that zim archive has been created before we + * formalize alias concept. But it would be still valid (from the spec) + * to have alias in the archive. + */ + bool mayHaveAliasEntry() const; + /** Get a shared ptr on the FileImpl * * @internal diff --git a/src/archive.cpp b/src/archive.cpp index 17f33157d..3454ec18b 100644 --- a/src/archive.cpp +++ b/src/archive.cpp @@ -487,6 +487,11 @@ namespace zim return m_impl->hasNewNamespaceScheme(); } + bool Archive::mayHaveAliasEntry() const + { + return m_impl->mayHaveAliasEntry(); + } + cluster_index_type Archive::getClusterCount() const { return cluster_index_type(m_impl->getCountClusters()); diff --git a/src/fileheader.cpp b/src/fileheader.cpp index e98509434..c719d9e25 100644 --- a/src/fileheader.cpp +++ b/src/fileheader.cpp @@ -41,7 +41,7 @@ namespace zim const uint32_t Fileheader::zimMagic = 0x044d495a; // ="ZIM^d" const uint16_t Fileheader::zimOldMajorVersion = 5; const uint16_t Fileheader::zimMajorVersion = 6; - const uint16_t Fileheader::zimMinorVersion = 1; + const uint16_t Fileheader::zimMinorVersion = 2; const offset_type Fileheader::size = 80; // This is also mimeListPos (so an offset) void Fileheader::write(int out_fd) const diff --git a/src/fileimpl.cpp b/src/fileimpl.cpp index 152f98aa0..89341aa01 100644 --- a/src/fileimpl.cpp +++ b/src/fileimpl.cpp @@ -599,6 +599,10 @@ class Grouping return zimReader->size(); } + bool FileImpl::mayHaveAliasEntry() const { + return header.getMinorVersion() >= 2; + } + bool FileImpl::is_multiPart() const { return zimFile->is_multiPart(); } diff --git a/src/fileimpl.h b/src/fileimpl.h index cc85c46d6..7e4d6c1af 100644 --- a/src/fileimpl.h +++ b/src/fileimpl.h @@ -115,6 +115,7 @@ namespace zim zsize_t getFilesize() const; bool hasNewNamespaceScheme() const { return m_newNamespaceScheme; } bool hasFrontArticlesIndex() const { return m_hasFrontArticlesIndex; } + bool mayHaveAliasEntry() const; FileCompound::PartRange getFileParts(offset_t offset, zsize_t size); std::shared_ptr getDirent(entry_index_t idx);