Kelson has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/304450 )
Change subject: Remove temporary ft_index.
......................................................................
Remove temporary ft_index.
Xapian indexer create temporary files while indexing content.
Remove those files at end.
Change-Id: I637da46f69a8f127052a48de5028c185fb0748aa
---
M zimwriterfs/tools.cpp
M zimwriterfs/tools.h
M zimwriterfs/xapianIndexer.cpp
M zimwriterfs/xapianIndexer.h
4 files changed, 31 insertions(+), 0 deletions(-)
Approvals:
Kelson: Verified; Looks good to me, approved
diff --git a/zimwriterfs/tools.cpp b/zimwriterfs/tools.cpp
index b73b5ca..af6d71d 100644
--- a/zimwriterfs/tools.cpp
+++ b/zimwriterfs/tools.cpp
@@ -31,6 +31,7 @@
#include <cerrno>
#include <sys/stat.h>
#include <magic.h>
+#include <dirent.h>
#include <unicode/translit.h>
#include <unicode/ucnv.h>
@@ -539,3 +540,19 @@
ustring.toUTF8String(unaccentedText);
return unaccentedText;
}
+
+void remove_all(const std::string& path) {
+ DIR *dir;
+ struct dirent *ent;
+ if ((dir = opendir (path.c_str())) != NULL) {
+ /* It's a directory, remove all its entries. */
+ while ((ent = readdir (dir)) != NULL) {
+ if (strcmp(ent->d_name, ".") and strcmp(ent->d_name, "..")) {
+ std::string childPath = path + SEPARATOR + ent->d_name;
+ remove_all(childPath);
+ }
+ }
+ closedir (dir);
+ }
+ remove(path.c_str());
+}
diff --git a/zimwriterfs/tools.h b/zimwriterfs/tools.h
index d85b292..bd7d6e6 100644
--- a/zimwriterfs/tools.h
+++ b/zimwriterfs/tools.h
@@ -47,4 +47,6 @@
std::string removeAccents(const std::string &text);
+void remove_all(const std::string& path);
+
#endif // OPENZIM_ZIMWRITERFS_TOOLS_H
diff --git a/zimwriterfs/xapianIndexer.cpp b/zimwriterfs/xapianIndexer.cpp
index 4d0effa..4117c14 100644
--- a/zimwriterfs/xapianIndexer.cpp
+++ b/zimwriterfs/xapianIndexer.cpp
@@ -32,6 +32,17 @@
*/
}
+XapianIndexer::~XapianIndexer(){
+ if (!indexPath.empty()) {
+ try {
+ remove_all(indexPath + ".tmp");
+ remove_all(indexPath);
+ } catch(...) {
+ /* Do not raise */
+ }
+ }
+}
+
void XapianIndexer::indexingPrelude(const string indexPath_) {
indexPath = indexPath_;
this->writableDatabase = Xapian::WritableDatabase(indexPath + ".tmp",
Xapian::DB_CREATE_OR_OVERWRITE);
diff --git a/zimwriterfs/xapianIndexer.h b/zimwriterfs/xapianIndexer.h
index 71dfe64..bbb170e 100644
--- a/zimwriterfs/xapianIndexer.h
+++ b/zimwriterfs/xapianIndexer.h
@@ -50,6 +50,7 @@
class XapianIndexer : public Indexer, public IHandler {
public:
XapianIndexer(const std::string& language, bool verbose);
+ virtual ~XapianIndexer();
std::string getIndexPath() { return indexPath; }
protected:
--
To view, visit https://gerrit.wikimedia.org/r/304450
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I637da46f69a8f127052a48de5028c185fb0748aa
Gerrit-PatchSet: 1
Gerrit-Project: openzim
Gerrit-Branch: master
Gerrit-Owner: Mgautierfr <[email protected]>
Gerrit-Reviewer: Kelson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits