Kelson has submitted this change and it was merged. Change subject: Bug fix: correctly update cluster offsets in directory entries. ......................................................................
Bug fix: correctly update cluster offsets in directory entries. This is a follow-up to f5de40f94b30795f42bb9388cbb46df9cd605167. When we moved the blob writing to the main dirent-creation loop, we ended up making separate *copies* of the dirents and updating blob/cluster information in these, instead of the dirents in the main list which will eventually be written. Make the auxilliary lists contain dirent *pointers* to avoid this problem. Change-Id: I008fa700acd90c3c51614bde65d61ffbc6061872 --- M zimlib/include/zim/writer/zimcreator.h M zimlib/src/zimcreator.cpp 2 files changed, 10 insertions(+), 9 deletions(-) Approvals: Kelson: Verified; Looks good to me, approved diff --git a/zimlib/include/zim/writer/zimcreator.h b/zimlib/include/zim/writer/zimcreator.h index 6f47402..2e52d7e 100644 --- a/zimlib/include/zim/writer/zimcreator.h +++ b/zimlib/include/zim/writer/zimcreator.h @@ -33,6 +33,7 @@ { public: typedef std::vector<Dirent> DirentsType; + typedef std::vector<Dirent*> DirentPtrsType; typedef std::vector<size_type> SizeVectorType; typedef std::vector<offset_type> OffsetsType; typedef std::map<std::string, uint16_t> MimeTypes; diff --git a/zimlib/src/zimcreator.cpp b/zimlib/src/zimcreator.cpp index bc977ea..46c550f 100644 --- a/zimlib/src/zimcreator.cpp +++ b/zimlib/src/zimcreator.cpp @@ -144,7 +144,7 @@ // because we don't know which one will fill up first. We also need // to track the dirents currently in each, so we can fix up the // cluster index if the other one ends up written first. - DirentsType compDirents, uncompDirents; + DirentPtrsType compDirents, uncompDirents; Cluster compCluster, uncompCluster; compCluster.setCompression(compression); uncompCluster.setCompression(zimcompNone); @@ -188,11 +188,11 @@ } } - dirents.push_back(dirent); currentSize += dirent.getDirentSize() /* for directory entry */ + sizeof(offset_type) /* for url pointer list */ + sizeof(size_type) /* for title pointer list */; + dirents.push_back(dirent); // If this is a redirect, we're done: there's no blob to add. if (dirent.isRedirect()) @@ -217,7 +217,7 @@ } Cluster *cluster; - DirentsType *myDirents, *otherDirents; + DirentPtrsType *myDirents, *otherDirents; if (dirent.isCompress()) { cluster = &compCluster; @@ -230,9 +230,9 @@ myDirents = &uncompDirents; otherDirents = &compDirents; } - myDirents->push_back(dirent); - dirent.setCluster(clusterOffsets.size(), cluster->count()); + dirents.back().setCluster(clusterOffsets.size(), cluster->count()); cluster->addBlob(blob); + myDirents->push_back(&(dirents.back())); // If cluster is now large enough, write it to disk. if (cluster->size() >= minChunkSize * 1024) @@ -247,10 +247,10 @@ cluster->clear(); myDirents->clear(); // Update the cluster number of the dirents *not* written to disk. - for (DirentsType::iterator di = otherDirents->begin(); + for (DirentPtrsType::iterator di = otherDirents->begin(); di != otherDirents->end(); ++di) { - di->setCluster(clusterOffsets.size(), di->getBlobNumber()); + (*di)->setCluster(clusterOffsets.size(), (*di)->getBlobNumber()); } offset_type end = out.tellp(); currentSize += (end - start) + @@ -263,10 +263,10 @@ { clusterOffsets.push_back(out.tellp()); out << compCluster; - for (DirentsType::iterator di = uncompDirents.begin(); + for (DirentPtrsType::iterator di = uncompDirents.begin(); di != uncompDirents.end(); ++di) { - di->setCluster(clusterOffsets.size(), di->getBlobNumber()); + (*di)->setCluster(clusterOffsets.size(), (*di)->getBlobNumber()); } } compCluster.clear(); -- To view, visit https://gerrit.wikimedia.org/r/296158 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I008fa700acd90c3c51614bde65d61ffbc6061872 Gerrit-PatchSet: 1 Gerrit-Project: openzim Gerrit-Branch: master Gerrit-Owner: Cscott <canan...@wikimedia.org> Gerrit-Reviewer: Kelson <kel...@kiwix.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits