Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to new api introduced in kiwix/libkiwix#991 #633

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- win32_dyn
include:
- target: native_static
image_variant: bionic
image_variant: focal
lib_postfix: '/x86_64-linux-gnu'
- target: native_dyn
image_variant: bionic
image_variant: focal
lib_postfix: '/x86_64-linux-gnu'
- target: win32_static
image_variant: f35
Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
fail-fast: false
matrix:
distro:
- ubuntu-kinetic
- ubuntu-jammy
- ubuntu-focal
steps:
Expand Down Expand Up @@ -41,14 +40,6 @@ jobs:
args: --no-sign
ppa: ${{ steps.ppa.outputs.ppa }}

- uses: legoktm/gh-action-build-deb@ubuntu-kinetic
if: matrix.distro == 'ubuntu-kinetic'
name: Build package for ubuntu-kinetic
id: build-ubuntu-kinetic
with:
args: --no-sign
ppa: ${{ steps.ppa.outputs.ppa }}

- uses: legoktm/gh-action-build-deb@ubuntu-focal
if: matrix.distro == 'ubuntu-focal'
name: Build package for ubuntu-focal
Expand Down
28 changes: 14 additions & 14 deletions src/manager/kiwix-manage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ using namespace std;

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

void show(kiwix::Library* library, const std::string& bookId)
void show(const kiwix::Library& library, const std::string& bookId)
{
try {
auto& book = library->getBookById(bookId);
auto& book = library.getBookById(bookId);
std::cout << "id:\t\t" << book.getId() << std::endl
<< "path:\t\t" << book.getPath() << std::endl
<< "url:\t\t" << book.getUrl() << std::endl
Expand Down Expand Up @@ -96,7 +96,7 @@ void usage()
<< std::endl;
}

int handle_show(kiwix::Library* library, const std::string& libraryPath,
int handle_show(const kiwix::Library& library, const std::string& libraryPath,
int argc, char* argv[])
{
if (argc > 3 ) {
Expand All @@ -105,15 +105,15 @@ int handle_show(kiwix::Library* library, const std::string& libraryPath,
show(library, bookId);
}
} else {
auto booksIds = library->getBooksIds();
auto booksIds = library.getBooksIds();
for(auto& bookId: booksIds) {
show(library, bookId);
}
}
return(0);
}

int handle_add(kiwix::Library* library, const std::string& libraryPath,
int handle_add(kiwix::LibraryPtr library, const std::string& libraryPath,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that a parameter of type kiwix::Library& is more suitable here (passing a shared_ptr suggests that it is preserved somewhere and can be accessed after the function returns).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pass the library to the Manager which take a LibraryPtr.
So I have keep LibraryPtr instead of kiwix::Library&.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the Manager object is completely internal to handle_add() (it no longer exists when the function returns) it would be perfectly safe to convert the Library& into a non-owning shared_ptr inside the function.

int argc, char* argv[])
{
string zimPath;
Expand Down Expand Up @@ -182,11 +182,11 @@ int handle_add(kiwix::Library* library, const std::string& libraryPath,
return(resultCode);
}

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

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

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

/* General argument parsing */
static struct option long_options[] = {
Expand Down Expand Up @@ -261,7 +261,7 @@ int main(int argc, char** argv)
libraryPath = kiwix::isRelativePath(libraryPath)
? kiwix::computeAbsolutePath(kiwix::getCurrentDirectory(), libraryPath)
: libraryPath;
kiwix::Manager manager(&library);
kiwix::Manager manager(library);
if (!manager.readFile(libraryPath, false)) {
if (kiwix::fileExists(libraryPath) || action!=ADD) {
std::cerr << "Cannot read the library " << libraryPath << std::endl;
Expand All @@ -273,13 +273,13 @@ int main(int argc, char** argv)
int exitCode = 0;
switch (action) {
case SHOW:
exitCode = handle_show(&library, libraryPath, argc, argv);
exitCode = handle_show(*library, libraryPath, argc, argv);
break;
case ADD:
exitCode = handle_add(&library, libraryPath, argc, argv);
exitCode = handle_add(library, libraryPath, argc, argv);
break;
case REMOVE:
exitCode = handle_remove(&library, libraryPath, argc, argv);
exitCode = handle_remove(*library, libraryPath, argc, argv);
break;
case NONE:
break;
Expand All @@ -292,7 +292,7 @@ int main(int argc, char** argv)
/* Rewrite the library file */
if (action == REMOVE || action == ADD) {
// writeToFile return true (1) if everything is ok => exitCode is 0
if (!library.writeToFile(libraryPath)) {
if (!library->writeToFile(libraryPath)) {
std::cerr << "Cannot write the library " << libraryPath << std::endl;
return 1;
}
Expand Down
12 changes: 6 additions & 6 deletions src/server/kiwix-serve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int main(int argc, char** argv)
#endif

std::string rootLocation = "/";
kiwix::Library library;
auto library = kiwix::Library::create();
unsigned int nb_threads = DEFAULT_THREADS;
std::vector<std::string> zimPathes;
std::string libraryPath;
Expand Down Expand Up @@ -331,7 +331,7 @@ int main(int argc, char** argv)
}

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

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

kiwix::UpdatableNameMapper nameMapper(library, noDateAliasesFlag);
kiwix::Server server(&library, &nameMapper);
auto nameMapper = std::make_shared<kiwix::UpdatableNameMapper>(library, noDateAliasesFlag);
kiwix::Server server(library, nameMapper);

if (!customIndexPath.empty()) {
try {
Expand Down Expand Up @@ -447,7 +447,7 @@ int main(int argc, char** argv)
if ( libraryMustBeReloaded && !libraryPaths.empty() ) {
libraryFileTimestamp = curLibraryFileTimestamp;
reloadLibrary(manager, libraryPaths);
nameMapper.update();
nameMapper->update();
libraryMustBeReloaded = false;
}
} while (waiting);
Expand Down
Loading