Check that 'M/Counter' exists before trying to read it.

Some old zim files may not have a 'Counter` metadata article.
We have to handle this correctly.
This commit is contained in:
Matthieu Gautier 2017-05-23 15:10:39 +02:00
parent d360b9143c
commit 7005b65901
1 changed files with 10 additions and 8 deletions

View File

@ -103,6 +103,7 @@ namespace kiwix {
zim::Article article = this->zimFileHandler->getArticle('M',"Counter"); zim::Article article = this->zimFileHandler->getArticle('M',"Counter");
if ( article.good() ) {
stringstream ssContent(article.getData()); stringstream ssContent(article.getData());
while(getline(ssContent, item, ';')) { while(getline(ssContent, item, ';')) {
@ -114,6 +115,7 @@ namespace kiwix {
counters.insert(pair<string, int>(mimeType, counter)); counters.insert(pair<string, int>(mimeType, counter));
} }
} }
}
return counters; return counters;
} }