diff --git a/src/common/kiwix/indexer.cpp b/src/common/kiwix/indexer.cpp index d84951d7f..99cb2870a 100644 --- a/src/common/kiwix/indexer.cpp +++ b/src/common/kiwix/indexer.cpp @@ -48,6 +48,7 @@ namespace kiwix { pthread_mutex_init(&articleIndexerRunningMutex, NULL); pthread_mutex_init(&articleCountMutex, NULL); pthread_mutex_init(&zimPathMutex, NULL); + pthread_mutex_init(&zimIdMutex, NULL); pthread_mutex_init(&indexPathMutex, NULL); pthread_mutex_init(&progressionMutex, NULL); pthread_mutex_init(&verboseMutex, NULL); @@ -70,10 +71,12 @@ namespace kiwix { pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); kiwix::Indexer *self = (kiwix::Indexer *)ptr; - /* Get the number of article to index */ + /* Get the number of article to index and the ZIM id */ kiwix::Reader reader(self->getZimPath()); unsigned int articleCount = reader.getGlobalCount(); self->setArticleCount(articleCount); + string zimId = reader.getId(); + self->setZimId(zimId); /* Progression */ unsigned int readArticleCount = 0; @@ -237,6 +240,11 @@ namespace kiwix { pthread_testcancel(); } self->indexingPostlude(); + + /* Write content id file */ + string path = appendToDirectory(self->getIndexPath(), "content.id"); + writeTextFile(path, self->getZimId()); + self->setProgression(100); #ifdef _WIN32 Sleep(100); @@ -405,6 +413,19 @@ namespace kiwix { return retVal; } + void Indexer::setZimId(const string id) { + pthread_mutex_lock(&zimIdMutex); + this->zimId = id; + pthread_mutex_unlock(&zimIdMutex); + } + + string Indexer::getZimId() { + pthread_mutex_lock(&zimIdMutex); + string retVal = this->zimId; + pthread_mutex_unlock(&zimIdMutex); + return retVal; + } + /* Manage */ bool Indexer::start(const string zimPath, const string indexPath) { if (this->getVerboseFlag()) { diff --git a/src/common/kiwix/indexer.h b/src/common/kiwix/indexer.h index f69d4933b..42476bb99 100644 --- a/src/common/kiwix/indexer.h +++ b/src/common/kiwix/indexer.h @@ -163,6 +163,12 @@ namespace kiwix { string indexPath; void setIndexPath(const string path); string getIndexPath(); + + /* ZIM id */ + pthread_mutex_t zimIdMutex; + string zimId; + void setZimId(const string id); + string getZimId(); }; } diff --git a/src/common/pathTools.cpp b/src/common/pathTools.cpp index 672234e2b..e30c3895f 100644 --- a/src/common/pathTools.cpp +++ b/src/common/pathTools.cpp @@ -97,6 +97,17 @@ string removeLastPathElement(const string path, const bool removePreSeparator, c return newPath; } +string appendToDirectory(const string &directoryPath, const string &filename) { +#ifdef _WIN32 + string separator = "\\"; +#else + string separator = "/"; +#endif + + string newPath = directoryPath + separator + filename; + return newPath; +} + string getLastPathElement(const string &path) { #ifdef _WIN32 string separator = "\\"; @@ -166,3 +177,11 @@ string getExecutablePath() { return std::string(binRootPath); } + +bool writeTextFile(const string &path, const string &content) { + std::ofstream file; + file.open(path); + file << content; + file.close(); + return true; +} diff --git a/src/common/pathTools.h b/src/common/pathTools.h index c829c0c73..3b5bc1942 100644 --- a/src/common/pathTools.h +++ b/src/common/pathTools.h @@ -42,6 +42,7 @@ bool isRelativePath(const string &path); string computeAbsolutePath(const string libraryPath, const string relativePath); string removeLastPathElement(const string path, const bool removePreSeparator = false, const bool removePostSeparator = false); +string appendToDirectory(const string &directoryPath, const string &filename); unsigned int getFileSize(const string &path); string getFileSizeAsString(const string &path); @@ -51,4 +52,5 @@ bool copyFile(const string &sourcePath, const string &destPath); string getLastPathElement(const string &path); string getExecutablePath(); +bool writeTextFile(const string &path, const string &content); #endif