diff --git a/ChangeLog b/ChangeLog index da5150df..db68a815 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2009-02-20 Jay Berkenbilt + * qpdf/qpdf.cc: in --check mode, if there are warnings but no + errors, exit with a status of 3. + * libqpdf/QPDF.cc (QPDF::insertXrefEntry): when recovering the cross-reference table, have objects we encounter later in the file supersede those we found earlier. This improves the chances of diff --git a/TODO b/TODO index e5097fb7..9f0c9ea5 100644 --- a/TODO +++ b/TODO @@ -4,9 +4,6 @@ * Spell check to fix types in messages and comments. Known type in "damanged". - * Exit with a different exit code if warning are found during check - mode. - General ======= diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml index 442285df..35e6aa81 100644 --- a/manual/qpdf-manual.xml +++ b/manual/qpdf-manual.xml @@ -741,7 +741,13 @@ make Checks file structure and well as encryption and linearization. A file for which reports no errors may still have errors in stream data but - should otherwise be otherwise structurally sound. + should otherwise be otherwise structurally sound. If + any errors, qpdf will exit with a + status of 2. There are some recoverable conditions that + detects. These are issued as + warnings instead of errors. If qpdf finds no errors but finds + warnings, it will exit with a status of 3 (as of + version 2.0.4). diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index d05f51ec..c7f3cbe0 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -875,7 +875,15 @@ int main(int argc, char* argv[]) } if (okay) { - std::cout << "No errors found" << std::endl; + if (! pdf.getWarnings().empty()) + { + // special exit status for warnings without errors + exit(3); + } + else + { + std::cout << "No errors found" << std::endl; + } } } } diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index 0fec2af5..7432edbd 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -152,7 +152,7 @@ for (my $i = 1; $i <= scalar(@badfiles); ++$i) show_ntests(); # ---------- $td->notify("--- Recovery Tests ---"); -$n_tests += @badfiles + 6; +$n_tests += @badfiles + 7; # Recovery tests. These are mostly after-the-fact -- when recovery # was implemented, some degree of recovery was possible on many of the @@ -211,6 +211,11 @@ $td->runtest("damaged replaced page contents", $td->runtest("check output", {$td->FILE => "a.pdf"}, {$td->FILE => "append-page-content-damaged.qdf"}); +$td->runtest("run check on damaged file", + {$td->COMMAND => "qpdf --check append-page-content-damaged.pdf"}, + {$td->FILE => "append-page-content-damaged-check.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); show_ntests(); # ---------- diff --git a/qpdf/qtest/qpdf/append-page-content-damaged-check.out b/qpdf/qtest/qpdf/append-page-content-damaged-check.out new file mode 100644 index 00000000..884de3a5 --- /dev/null +++ b/qpdf/qtest/qpdf/append-page-content-damaged-check.out @@ -0,0 +1,6 @@ +WARNING: append-page-content-damaged.pdf: offset 0: file is damaged +WARNING: append-page-content-damaged.pdf: can't find startxref +WARNING: Attempting to reconstruct cross-reference table +checking append-page-content-damaged.pdf +File is not encrypted +File is not linearized