@@ -188,7 +188,7 @@ class Grouping
188
188
{}
189
189
#endif
190
190
191
- FileImpl::FileImpl (std::shared_ptr<FileCompound> _zimFile) try
191
+ FileImpl::FileImpl (std::shared_ptr<FileCompound> _zimFile)
192
192
: zimFile (_zimFile),
193
193
zimReader (makeFileReader (zimFile)),
194
194
direntReader (new DirentReader (zimReader)),
@@ -248,33 +248,42 @@ class Grouping
248
248
const_cast <entry_index_t &>(m_endUserEntry) = getCountArticles ();
249
249
}
250
250
251
- auto result = tmp_direntLookup.find (' X' , " listing/titleOrdered/v1" );
252
- if (result.first ) {
253
- mp_titleDirentAccessor = getTitleAccessorV1 (result.second );
254
- }
255
251
256
- if (!mp_titleDirentAccessor) {
257
- if (!header.hasTitleListingV0 ()) {
258
- throw ZimFileFormatError (" Zim file doesn't contain a title ordered index" );
252
+ // Following code will may create cluster and
253
+ try {
254
+ auto result = tmp_direntLookup.find (' X' , " listing/titleOrdered/v1" );
255
+ if (result.first ) {
256
+ mp_titleDirentAccessor = getTitleAccessorV1 (result.second );
259
257
}
260
- offset_t titleOffset (header.getTitleIdxPos ());
261
- zsize_t titleSize (sizeof (entry_index_type)*header.getArticleCount ());
262
- mp_titleDirentAccessor = getTitleAccessor (titleOffset, titleSize, " Title index table" );
263
- const_cast <bool &>(m_hasFrontArticlesIndex) = false ;
264
- }
265
- m_byTitleDirentLookup.reset (new ByTitleDirentLookup (mp_titleDirentAccessor.get ()));
266
258
267
- readMimeTypes ();
268
- } catch (...) {
269
- getClusterCache ().drop_all ([=](const std::tuple<FileImpl*, cluster_index_type>& key) {return std::get<0 >(key) == this ;});
270
- throw ;
259
+ if (!mp_titleDirentAccessor) {
260
+ if (!header.hasTitleListingV0 ()) {
261
+ throw ZimFileFormatError (" Zim file doesn't contain a title ordered index" );
262
+ }
263
+ offset_t titleOffset (header.getTitleIdxPos ());
264
+ zsize_t titleSize (sizeof (entry_index_type)*header.getArticleCount ());
265
+ mp_titleDirentAccessor = getTitleAccessor (titleOffset, titleSize, " Title index table" );
266
+ const_cast <bool &>(m_hasFrontArticlesIndex) = false ;
267
+ }
268
+ m_byTitleDirentLookup.reset (new ByTitleDirentLookup (mp_titleDirentAccessor.get ()));
269
+
270
+ readMimeTypes ();
271
+ } catch (...) {
272
+ dropCachedCluster ();
273
+ throw ;
274
+ }
271
275
}
272
276
273
277
FileImpl::~FileImpl () {
274
278
// We have to clean the global cache for our clusters.
279
+ dropCachedCluster ();
280
+ }
281
+
282
+ void FileImpl::dropCachedCluster () const {
275
283
getClusterCache ().drop_all ([=](const std::tuple<FileImpl*, cluster_index_type>& key) {return std::get<0 >(key) == this ;});
276
284
}
277
285
286
+
278
287
std::unique_ptr<IndirectDirentAccessor> FileImpl::getTitleAccessorV1 (const entry_index_t idx)
279
288
{
280
289
auto dirent = mp_pathDirentAccessor->getDirent (idx);
0 commit comments