Skip to content

Commit 018df0d

Browse files
committed
Adapt to new api introduced in kiwix/libkiwix#991
1 parent 76ac5ce commit 018df0d

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/manager/kiwix-manage.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ using namespace std;
2929

3030
enum supportedAction { NONE, ADD, SHOW, REMOVE };
3131

32-
void show(kiwix::Library* library, const std::string& bookId)
32+
void show(const kiwix::Library& library, const std::string& bookId)
3333
{
3434
try {
35-
auto& book = library->getBookById(bookId);
35+
auto& book = library.getBookById(bookId);
3636
std::cout << "id:\t\t" << book.getId() << std::endl
3737
<< "path:\t\t" << book.getPath() << std::endl
3838
<< "url:\t\t" << book.getUrl() << std::endl
@@ -96,7 +96,7 @@ void usage()
9696
<< std::endl;
9797
}
9898

99-
int handle_show(kiwix::Library* library, const std::string& libraryPath,
99+
int handle_show(const kiwix::Library& library, const std::string& libraryPath,
100100
int argc, char* argv[])
101101
{
102102
if (argc > 3 ) {
@@ -105,15 +105,15 @@ int handle_show(kiwix::Library* library, const std::string& libraryPath,
105105
show(library, bookId);
106106
}
107107
} else {
108-
auto booksIds = library->getBooksIds();
108+
auto booksIds = library.getBooksIds();
109109
for(auto& bookId: booksIds) {
110110
show(library, bookId);
111111
}
112112
}
113113
return(0);
114114
}
115115

116-
int handle_add(kiwix::Library* library, const std::string& libraryPath,
116+
int handle_add(kiwix::LibraryPtr library, const std::string& libraryPath,
117117
int argc, char* argv[])
118118
{
119119
string zimPath;
@@ -182,11 +182,11 @@ int handle_add(kiwix::Library* library, const std::string& libraryPath,
182182
return(resultCode);
183183
}
184184

185-
int handle_remove(kiwix::Library* library, const std::string& libraryPath,
185+
int handle_remove(kiwix::Library& library, const std::string& libraryPath,
186186
int argc, char* argv[])
187187
{
188188
std::string bookId;
189-
const unsigned int totalBookCount = library->getBookCount(true, true);
189+
const unsigned int totalBookCount = library.getBookCount(true, true);
190190
int exitCode = 0;
191191

192192
if (argc <= 3) {
@@ -203,7 +203,7 @@ int handle_remove(kiwix::Library* library, const std::string& libraryPath,
203203
for (int i = 3; i<argc; i++) {
204204
bookId = argv[i];
205205

206-
if (!library->removeBookById(bookId)) {
206+
if (!library.removeBookById(bookId)) {
207207
std::cerr << "Invalid book id '" << bookId << "'." << std::endl;
208208
exitCode = 1;
209209
}
@@ -216,7 +216,7 @@ int main(int argc, char** argv)
216216
{
217217
string libraryPath = "";
218218
supportedAction action = NONE;
219-
kiwix::Library library;
219+
auto library = kiwix::Library::create();
220220

221221
/* General argument parsing */
222222
static struct option long_options[] = {
@@ -261,7 +261,7 @@ int main(int argc, char** argv)
261261
libraryPath = kiwix::isRelativePath(libraryPath)
262262
? kiwix::computeAbsolutePath(kiwix::getCurrentDirectory(), libraryPath)
263263
: libraryPath;
264-
kiwix::Manager manager(&library);
264+
kiwix::Manager manager(library);
265265
if (!manager.readFile(libraryPath, false)) {
266266
if (kiwix::fileExists(libraryPath) || action!=ADD) {
267267
std::cerr << "Cannot read the library " << libraryPath << std::endl;
@@ -273,13 +273,13 @@ int main(int argc, char** argv)
273273
int exitCode = 0;
274274
switch (action) {
275275
case SHOW:
276-
exitCode = handle_show(&library, libraryPath, argc, argv);
276+
exitCode = handle_show(*library, libraryPath, argc, argv);
277277
break;
278278
case ADD:
279-
exitCode = handle_add(&library, libraryPath, argc, argv);
279+
exitCode = handle_add(library, libraryPath, argc, argv);
280280
break;
281281
case REMOVE:
282-
exitCode = handle_remove(&library, libraryPath, argc, argv);
282+
exitCode = handle_remove(*library, libraryPath, argc, argv);
283283
break;
284284
case NONE:
285285
break;
@@ -292,7 +292,7 @@ int main(int argc, char** argv)
292292
/* Rewrite the library file */
293293
if (action == REMOVE || action == ADD) {
294294
// writeToFile return true (1) if everything is ok => exitCode is 0
295-
if (!library.writeToFile(libraryPath)) {
295+
if (!library->writeToFile(libraryPath)) {
296296
std::cerr << "Cannot write the library " << libraryPath << std::endl;
297297
return 1;
298298
}

src/server/kiwix-serve.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int main(int argc, char** argv)
197197
#endif
198198

199199
std::string rootLocation = "/";
200-
kiwix::Library library;
200+
auto library = kiwix::Library::create();
201201
unsigned int nb_threads = DEFAULT_THREADS;
202202
std::vector<std::string> zimPathes;
203203
std::string libraryPath;
@@ -331,7 +331,7 @@ int main(int argc, char** argv)
331331
}
332332

333333
/* Setup the library manager and get the list of books */
334-
kiwix::Manager manager(&library);
334+
kiwix::Manager manager(library);
335335
std::vector<std::string> libraryPaths;
336336
if (libraryFlag) {
337337
libraryPaths = kiwix::split(libraryPath, ";");
@@ -340,7 +340,7 @@ int main(int argc, char** argv)
340340
}
341341

342342
/* Check if the library is not empty (or only remote books)*/
343-
if (library.getBookCount(true, false) == 0) {
343+
if (library->getBookCount(true, false) == 0) {
344344
std::cerr << "The XML library file '" << libraryPath
345345
<< "' is empty (or has only remote books)." << std::endl;
346346
}
@@ -376,8 +376,8 @@ int main(int argc, char** argv)
376376
}
377377
#endif
378378

379-
kiwix::UpdatableNameMapper nameMapper(library, noDateAliasesFlag);
380-
kiwix::Server server(&library, &nameMapper);
379+
auto nameMapper = std::make_shared<kiwix::UpdatableNameMapper>(library, noDateAliasesFlag);
380+
kiwix::Server server(library, nameMapper);
381381

382382
if (!customIndexPath.empty()) {
383383
try {
@@ -447,7 +447,7 @@ int main(int argc, char** argv)
447447
if ( libraryMustBeReloaded && !libraryPaths.empty() ) {
448448
libraryFileTimestamp = curLibraryFileTimestamp;
449449
reloadLibrary(manager, libraryPaths);
450-
nameMapper.update();
450+
nameMapper->update();
451451
libraryMustBeReloaded = false;
452452
}
453453
} while (waiting);

0 commit comments

Comments
 (0)