3
0
Fork 0

+ few performance improvement

small_fixes
kelson42 14 years ago
parent 0bd8c57a23
commit a21667b4cc

@ -152,37 +152,47 @@ int main(int argc, char **argv) {
/* Copy the file to the data/content directory */ /* Copy the file to the data/content directory */
string newContentPath = computeAbsolutePath(dataContentPath, contentFilename); string newContentPath = computeAbsolutePath(dataContentPath, contentFilename);
copyFile(contentPath, newContentPath); if (!fileExists(newContentPath) || getFileSize(contentPath) != getFileSize(newContentPath)) {
copyFile(contentPath, newContentPath);
/* Add the file to the library.xml */
string libraryPath = computeAbsolutePath(dataLibraryPath, contentFilename + ".xml");
kiwix::Manager libraryManager;
if (libraryManager.addBookFromPath(newContentPath, "../content/" + contentFilename, "", false)) {
libraryManager.writeFile(libraryPath);
} else {
cerr << "Unable to build or save library file '" << libraryPath << "'" << endl;
} }
/* Index the file if necessary */ /* Index the file if necessary */
string indexPath = computeAbsolutePath(dataIndexPath, contentFilename + ".idx"); string indexFilename = contentFilename + ".idx";
kiwix::Indexer *indexer = NULL; string indexPath = computeAbsolutePath(dataIndexPath, indexFilename);
try { if (buildIndexFlag && !fileExists(indexPath)) {
if (backend == CLUCENE) { kiwix::Indexer *indexer = NULL;
indexer = new kiwix::CluceneIndexer(contentPath, indexPath); try {
if (backend == CLUCENE) {
indexer = new kiwix::CluceneIndexer(contentPath, indexPath);
} else {
indexer = new kiwix::XapianIndexer(contentPath, indexPath);
}
} catch (...) {
cerr << "Unable to index '" << contentPath << "'." << endl;
exit(1);
}
if (indexer != NULL) {
while (indexer->indexNextPercent(verboseFlag)) {};
delete indexer;
} else { } else {
indexer = new kiwix::XapianIndexer(contentPath, indexPath); cerr << "Unable instanciate the Kiwix indexer." << endl;
exit(1);
} }
} catch (...) {
cerr << "Unable to index '" << contentPath << "'." << endl;
exit(1);
} }
if (indexer != NULL) { /* Add the file to the library.xml */
while (indexer->indexNextPercent(verboseFlag)) {}; kiwix::Manager libraryManager;
delete indexer; string libraryPath = computeAbsolutePath(dataLibraryPath, contentFilename + ".xml");
string bookId = libraryManager.addBookFromPathAndGetId(newContentPath, "../content/" + contentFilename, "", false);
if (!bookId.empty()) {
libraryManager.setCurrentBookId(bookId);
if (buildIndexFlag) {
libraryManager.setBookIndex(bookId, "../index/" + indexFilename, kiwix::XAPIAN);
}
libraryManager.writeFile(libraryPath);
} else { } else {
cerr << "Unable instanciate the Kiwix indexer." << endl; cerr << "Unable to build or save library file '" << libraryPath << "'" << endl;
exit(1);
} }
} }

Loading…
Cancel
Save