mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Fix input file = output file test for split pages
This commit is contained in:
parent
be3a8c0e7a
commit
039eb4a253
@ -1,3 +1,9 @@
|
|||||||
|
2021-02-23 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
|
* The test for the input and output files being the same wasn't
|
||||||
|
implemented correctly for --split-pages since the specified output
|
||||||
|
file is really a pattern, not the actual output file.
|
||||||
|
|
||||||
2021-02-22 Jay Berkenbilt <ejb@ql.org>
|
2021-02-22 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
* From qpdf CLI, --pages and --split-pages will properly preserve
|
* From qpdf CLI, --pages and --split-pages will properly preserve
|
||||||
|
@ -3738,7 +3738,7 @@ ArgParser::doFinalChecks()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QUtil::same_file(o.infilename, o.outfilename))
|
if ((! o.split_pages) && QUtil::same_file(o.infilename, o.outfilename))
|
||||||
{
|
{
|
||||||
QTC::TC("qpdf", "qpdf same file error");
|
QTC::TC("qpdf", "qpdf same file error");
|
||||||
usage("input file and output file are the same;"
|
usage("input file and output file are the same;"
|
||||||
@ -6389,6 +6389,13 @@ static void do_split_pages(QPDF& pdf, Options& o, bool& warnings)
|
|||||||
QUtil::uint_to_string(last, QIntC::to_int(pageno_len));
|
QUtil::uint_to_string(last, QIntC::to_int(pageno_len));
|
||||||
}
|
}
|
||||||
std::string outfile = before + page_range + after;
|
std::string outfile = before + page_range + after;
|
||||||
|
if (QUtil::same_file(o.infilename, outfile.c_str()))
|
||||||
|
{
|
||||||
|
std::cerr << whoami
|
||||||
|
<< ": split pages would overwrite input file with "
|
||||||
|
<< outfile << std::endl;
|
||||||
|
exit(EXIT_ERROR);
|
||||||
|
}
|
||||||
QPDFWriter w(outpdf, outfile.c_str());
|
QPDFWriter w(outpdf, outfile.c_str());
|
||||||
set_writer_options(outpdf, o, w);
|
set_writer_options(outpdf, o, w);
|
||||||
w.write();
|
w.write();
|
||||||
|
@ -1825,14 +1825,24 @@ $td->runtest("out of range in deleted object",
|
|||||||
show_ntests();
|
show_ntests();
|
||||||
# ----------
|
# ----------
|
||||||
$td->notify("--- Overwrite self ---");
|
$td->notify("--- Overwrite self ---");
|
||||||
$n_tests += 1;
|
$n_tests += 3;
|
||||||
|
|
||||||
copy("minimal.pdf", "a.pdf");
|
copy("minimal.pdf", "a.pdf");
|
||||||
|
copy("minimal.pdf", "split-out.pdf");
|
||||||
# Also tests @- for reading args from stdin
|
# Also tests @- for reading args from stdin
|
||||||
$td->runtest("don't overwrite self",
|
$td->runtest("don't overwrite self",
|
||||||
{$td->COMMAND => "(echo a.pdf; echo a.pdf) | qpdf \@-"},
|
{$td->COMMAND => "(echo a.pdf; echo a.pdf) | qpdf \@-"},
|
||||||
{$td->REGEXP => "input file and output file are the same.*",
|
{$td->REGEXP => "input file and output file are the same.*",
|
||||||
$td->EXIT_STATUS => 2});
|
$td->EXIT_STATUS => 2});
|
||||||
|
$td->runtest("output is not really output for split",
|
||||||
|
{$td->COMMAND => "qpdf --split-pages split-out.pdf split-out.pdf"},
|
||||||
|
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||||
|
$td->runtest("don't overwrite self (split)",
|
||||||
|
{$td->COMMAND =>
|
||||||
|
"qpdf --split-pages split-out-1.pdf split-out.pdf"},
|
||||||
|
{$td->REGEXP =>
|
||||||
|
".*split pages would overwrite.* split-out-1.pdf",
|
||||||
|
$td->EXIT_STATUS => 2});
|
||||||
|
|
||||||
show_ntests();
|
show_ntests();
|
||||||
# ----------
|
# ----------
|
||||||
|
Loading…
Reference in New Issue
Block a user