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

Fix zimwriterfs and missing magic file. #374

Merged
merged 5 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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ distribution. Try then with a source tarball distributed by the
problematic upstream project or even directly from the source code
repository.

### Magic File

`zimwriterfs` use libmagic to detect the mimetype of files to add.
It needs to load the magic database. Most of the time, this file is already present
in your system and everything works.
But sometime, this file may be not present or cannot be found.
You can set the `MAGIC` environment variable to point to this file.

`zimwriterfs` will refuse to run if this file is not found. You can force
it to run passing the option `--skip-libmagic-check`.

License
-------

Expand Down
26 changes: 22 additions & 4 deletions src/zimwriterfs/zimwriterfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
bool withoutFTIndex = false;
bool noUuid = false;
bool dontCheckArgs = false;
bool continue_without_magic = false;

bool thereAreMissingArguments()
{
Expand Down Expand Up @@ -149,6 +150,13 @@
return retVal;
}

void printZimWriterFsVersions(std::ostream& out = std::cout) {
out << "zim-tools " << VERSION << std::endl;
out << "+ libmagic " << magic_version() << std::endl;
out << std::endl;
zim::printVersions(out);
}

Check warning on line 158 in src/zimwriterfs/zimwriterfs.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimwriterfs/zimwriterfs.cpp#L153-L158

Added lines #L153 - L158 were not covered by tests

/* Print correct console usage options */
void usage()
{
Expand Down Expand Up @@ -216,6 +224,7 @@
<< std::endl;
std::cout << "\t-s, --scraper\t\tname & version of tool used to produce HTML content"
<< std::endl;
std::cout << "\t--skip-libmagic-check\tAccept to run even if magic file cannot be loaded (mimetypes in the zim file may be wrong)." << std::endl;

Check warning on line 227 in src/zimwriterfs/zimwriterfs.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimwriterfs/zimwriterfs.cpp#L227

Added line #L227 was not covered by tests
// --no-uuid and --dont-check-arguments are dev options, let's keep them secret
// std::cout << "\t-U, --no-uuid\t\tdon't generate a random UUID" << std::endl;
// std::cout << "\t-B, --dont-check-arguments\t\tdon't check arguments (and possibly produce a broken ZIM file)" << std::endl;
Expand Down Expand Up @@ -263,6 +272,7 @@
{"threads", required_argument, 0, 'J'},
{"no-uuid", no_argument, 0, 'U'},
{"dont-check-arguments", no_argument, 0, 'B'},
{"skip-libmagic-check", no_argument, 0, 'M'},

// Only for backward compatibility
{"withFullTextIndex", no_argument, 0, 'i'},
Expand All @@ -281,7 +291,7 @@
tags = optarg;
break;
case 'V':
printVersions();
printZimWriterFsVersions();
exit(0);
break;
case 'h':
Expand Down Expand Up @@ -351,6 +361,9 @@
case 'B':
dontCheckArgs = true;
break;
case 'M':
continue_without_magic = true;
break;

Check warning on line 366 in src/zimwriterfs/zimwriterfs.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimwriterfs/zimwriterfs.cpp#L364-L366

Added lines #L364 - L366 were not covered by tests
}
}
} while (c != -1);
Expand Down Expand Up @@ -475,14 +488,19 @@
/* Main program entry point */
int main(int argc, char** argv)
{
parse_args(argc, argv);

Check warning on line 491 in src/zimwriterfs/zimwriterfs.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimwriterfs/zimwriterfs.cpp#L491

Added line #L491 was not covered by tests

/* Init */
magic = magic_open(MAGIC_MIME);
magic_load(magic, NULL);
if (magic_load(magic, NULL) != 0) {
std::cerr << "Impossible to load magic file. Set `MAGIC` environment variable to a `magic` (or `magic.mgc`) file." << std::endl;

Check warning on line 496 in src/zimwriterfs/zimwriterfs.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimwriterfs/zimwriterfs.cpp#L496

Added line #L496 was not covered by tests
if (! continue_without_magic) {
exit(1);

Check warning on line 498 in src/zimwriterfs/zimwriterfs.cpp

View check run for this annotation

Codecov / codecov/patch

src/zimwriterfs/zimwriterfs.cpp#L498

Added line #L498 was not covered by tests
}
}
pthread_mutex_init(&verboseMutex, NULL);

try {
parse_args(argc, argv);

const zim::Metadata metadata = makeMetadata();

if ( !checkMetadata(metadata) ) {
Expand Down
Loading