Commit 6048c6e2f06e21ebbe143df422dccd9bb50a3f6f
1 parent
968e7e60
Don't crash on @file when file doesn't exist (fixes #265)
When @file is used and file doesn't exist, just treat it as a normal argument.
Showing
4 changed files
with
36 additions
and
2 deletions
ChangeLog
| 1 | 2018-12-23 Jay Berkenbilt <ejb@ql.org> | 1 | 2018-12-23 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | ||
| 3 | + * When specifying @arg on the command line, if the file "arg" does | ||
| 4 | + not exist, just treat this is a normal argument. This makes it | ||
| 5 | + easier to deal with files whose names start with the @ character. | ||
| 6 | + Fixes #265. | ||
| 7 | + | ||
| 3 | * Tweak completion so it works with zsh as well using | 8 | * Tweak completion so it works with zsh as well using |
| 4 | bashcompinit. | 9 | bashcompinit. |
| 5 | 10 |
qpdf/qpdf.cc
| @@ -1408,8 +1408,25 @@ ArgParser::handleArgFileArguments() | @@ -1408,8 +1408,25 @@ ArgParser::handleArgFileArguments() | ||
| 1408 | new_argv.push_back(PointerHolder<char>(true, QUtil::copy_string(argv[0]))); | 1408 | new_argv.push_back(PointerHolder<char>(true, QUtil::copy_string(argv[0]))); |
| 1409 | for (int i = 1; i < argc; ++i) | 1409 | for (int i = 1; i < argc; ++i) |
| 1410 | { | 1410 | { |
| 1411 | + char* argfile = 0; | ||
| 1411 | if ((strlen(argv[i]) > 1) && (argv[i][0] == '@')) | 1412 | if ((strlen(argv[i]) > 1) && (argv[i][0] == '@')) |
| 1412 | { | 1413 | { |
| 1414 | + try | ||
| 1415 | + { | ||
| 1416 | + argfile = 1 + argv[i]; | ||
| 1417 | + if (strcmp(argfile, "-") != 0) | ||
| 1418 | + { | ||
| 1419 | + fclose(QUtil::safe_fopen(argfile, "rb")); | ||
| 1420 | + } | ||
| 1421 | + } | ||
| 1422 | + catch (std::runtime_error&) | ||
| 1423 | + { | ||
| 1424 | + // The file's not there; treating as regular option | ||
| 1425 | + argfile = 0; | ||
| 1426 | + } | ||
| 1427 | + } | ||
| 1428 | + if (argfile) | ||
| 1429 | + { | ||
| 1413 | readArgsFromFile(1+argv[i]); | 1430 | readArgsFromFile(1+argv[i]); |
| 1414 | } | 1431 | } |
| 1415 | else | 1432 | else |
qpdf/qtest/qpdf.test
| @@ -150,7 +150,7 @@ foreach my $c (@completion_tests) | @@ -150,7 +150,7 @@ foreach my $c (@completion_tests) | ||
| 150 | show_ntests(); | 150 | show_ntests(); |
| 151 | # ---------- | 151 | # ---------- |
| 152 | $td->notify("--- Argument Parsing ---"); | 152 | $td->notify("--- Argument Parsing ---"); |
| 153 | -$n_tests += 3; | 153 | +$n_tests += 4; |
| 154 | 154 | ||
| 155 | $td->runtest("required argument", | 155 | $td->runtest("required argument", |
| 156 | {$td->COMMAND => "qpdf --password minimal.pdf"}, | 156 | {$td->COMMAND => "qpdf --password minimal.pdf"}, |
| @@ -167,6 +167,11 @@ $td->runtest("required argument with choices", | @@ -167,6 +167,11 @@ $td->runtest("required argument with choices", | ||
| 167 | {$td->REGEXP => "must be given as --decode-level=\\{.*all.*\\}", | 167 | {$td->REGEXP => "must be given as --decode-level=\\{.*all.*\\}", |
| 168 | $td->EXIT_STATUS => 2}, | 168 | $td->EXIT_STATUS => 2}, |
| 169 | $td->NORMALIZE_NEWLINES); | 169 | $td->NORMALIZE_NEWLINES); |
| 170 | +copy("minimal.pdf", '@file.pdf'); | ||
| 171 | +$td->runtest("\@file exists and file doesn't", | ||
| 172 | + {$td->COMMAND => "qpdf --check \@file.pdf"}, | ||
| 173 | + {$td->FILE => "check-at-file.out", $td->EXIT_STATUS => 0}, | ||
| 174 | + $td->NORMALIZE_NEWLINES); | ||
| 170 | 175 | ||
| 171 | show_ntests(); | 176 | show_ntests(); |
| 172 | # ---------- | 177 | # ---------- |
| @@ -1100,6 +1105,7 @@ $td->notify("--- Overwrite self ---"); | @@ -1100,6 +1105,7 @@ $td->notify("--- Overwrite self ---"); | ||
| 1100 | $n_tests += 1; | 1105 | $n_tests += 1; |
| 1101 | 1106 | ||
| 1102 | copy("minimal.pdf", "a.pdf"); | 1107 | copy("minimal.pdf", "a.pdf"); |
| 1108 | +# Also tests @- for reading args from stdin | ||
| 1103 | $td->runtest("don't overwrite self", | 1109 | $td->runtest("don't overwrite self", |
| 1104 | {$td->COMMAND => "(echo a.pdf; echo a.pdf) | qpdf \@-"}, | 1110 | {$td->COMMAND => "(echo a.pdf; echo a.pdf) | qpdf \@-"}, |
| 1105 | {$td->REGEXP => "input file and output file are the same.*", | 1111 | {$td->REGEXP => "input file and output file are the same.*", |
| @@ -3384,5 +3390,5 @@ sub get_md5_checksum | @@ -3384,5 +3390,5 @@ sub get_md5_checksum | ||
| 3384 | sub cleanup | 3390 | sub cleanup |
| 3385 | { | 3391 | { |
| 3386 | system("rm -rf *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache"); | 3392 | system("rm -rf *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache"); |
| 3387 | - system("rm -rf *split-out* ???-kfo.pdf *.tmpout"); | 3393 | + system("rm -rf *split-out* ???-kfo.pdf *.tmpout \@file.pdf"); |
| 3388 | } | 3394 | } |