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

kiwix-serve: Skip invalid ZIM files and continue startup #659 #666

Merged
merged 3 commits into from
Mar 13, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/man/kiwix-serve.1
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ Override the welcome page with a custom HTML file.
\fB-L N, --ipConnectionLimit=N\fR
Max number of (concurrent) connections per IP (default: infinite, recommended: >= 6).

.TP
\fB-k, --skipInvalid\fR
Startup even when ZIM files are invalid (those will be skipped)

.TP
\fB-v, --verbose\fR
Print debug log to STDOUT.
Expand Down
16 changes: 13 additions & 3 deletions src/server/kiwix-serve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void usage()
<< "\t-z, --nodatealiases\tCreate URL aliases for each content by removing the date" << std::endl
<< "\t-c, --customIndex\tAdd path to custom index.html for welcome page" << std::endl
<< "\t-L, --ipConnectionLimit\tMax number of (concurrent) connections per IP (default: infinite, recommended: >= 6)" << std::endl
<< "\t-k, --skipInvalid\tStartup even when ZIM files are invalid (those will be skipped)" << std::endl
<< std::endl

<< "Documentation:" << std::endl
Expand Down Expand Up @@ -217,6 +218,7 @@ int main(int argc, char** argv)
unsigned int PPID = 0;
int ipConnectionLimit = 0;
int searchLimit = 0;
bool skipInvalid = false;

static struct option long_options[]
= {{"daemon", no_argument, 0, 'd'},
Expand All @@ -237,6 +239,7 @@ int main(int argc, char** argv)
{"monitorLibrary", no_argument, 0, 'M'},
{"ipConnectionLimit", required_argument, 0, 'L'},
{"searchLimit", required_argument, 0, 's'},
{"skipInvalid", no_argument, 0, 'k'},
{0, 0, 0, 0}};

std::set<int> usedOptions;
Expand Down Expand Up @@ -307,6 +310,9 @@ int main(int argc, char** argv)
case 's':
searchLimit = atoi(optarg);
break;
case 'k':
skipInvalid = true;
break;
case '?':
usage();
return 2;
Expand Down Expand Up @@ -348,9 +354,13 @@ int main(int argc, char** argv)
std::vector<std::string>::iterator it;
for (it = zimPathes.begin(); it != zimPathes.end(); it++) {
if (!manager.addBookFromPath(*it, *it, "", false)) {
std::cerr << "Unable to add the ZIM file '" << *it
<< "' to the internal library." << std::endl;
exit(1);
if (skipInvalid) {
std::cerr << "Skipping invalid '" << *it << "' ...continuing" << std::endl;
} else {
std::cerr << "Unable to add the ZIM file '" << *it
<< "' to the internal library." << std::endl;
exit(1);
}
}
}
}
Expand Down