mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Make --replace-input work with / in path (fixes #365)
This commit is contained in:
parent
bcfb0c7d9a
commit
e188d0fffa
@ -1,3 +1,9 @@
|
|||||||
|
2019-10-12 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
|
* Change the name of the temporary file used by --replace-input to
|
||||||
|
work with arbitrary absolute or relative paths without requiring
|
||||||
|
path splitting logic. Fixes #365.
|
||||||
|
|
||||||
2019-09-20 Jay Berkenbilt <ejb@ql.org>
|
2019-09-20 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
* 9.0.1: release
|
* 9.0.1: release
|
||||||
|
@ -458,7 +458,7 @@ make
|
|||||||
If specified, the output file name should be omitted. This
|
If specified, the output file name should be omitted. This
|
||||||
option tells qpdf to replace the input file with the output.
|
option tells qpdf to replace the input file with the output.
|
||||||
It does this by writing to
|
It does this by writing to
|
||||||
<filename>.~qpdf-temp.<replaceable>infilename</replaceable>#</filename>
|
<filename><replaceable>infilename</replaceable>.~qpdf-temp#</filename>
|
||||||
and, when done, overwriting the input file with the temporary
|
and, when done, overwriting the input file with the temporary
|
||||||
file. If there were any warnings, the original input is saved
|
file. If there were any warnings, the original input is saved
|
||||||
as
|
as
|
||||||
@ -4364,6 +4364,27 @@ print "\n";
|
|||||||
<filename>ChangeLog</filename> in the source distribution.
|
<filename>ChangeLog</filename> in the source distribution.
|
||||||
</para>
|
</para>
|
||||||
<variablelist>
|
<variablelist>
|
||||||
|
<varlistentry>
|
||||||
|
<term>9.0.2: XXX</term>
|
||||||
|
<listitem>
|
||||||
|
<itemizedlist>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Bug Fix
|
||||||
|
</para>
|
||||||
|
<itemizedlist>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Fix the name of the temporary file used by
|
||||||
|
<option>--replace-input</option> so that it doesn't require
|
||||||
|
path splitting and works with paths include directories.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
</listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>9.0.1: September 20, 2019</term>
|
<term>9.0.1: September 20, 2019</term>
|
||||||
<listitem>
|
<listitem>
|
||||||
|
22
qpdf/qpdf.cc
22
qpdf/qpdf.cc
@ -5148,11 +5148,10 @@ static void write_outfile(QPDF& pdf, Options& o)
|
|||||||
std::string temp_out;
|
std::string temp_out;
|
||||||
if (o.replace_input)
|
if (o.replace_input)
|
||||||
{
|
{
|
||||||
// Use a file name that is hidden by default in the OS to
|
// Append but don't prepend to the path to generate a
|
||||||
// avoid having it become momentarily visible in a
|
// temporary name. This saves us from having to split the path
|
||||||
// graphical file manager or in case it gets left behind
|
// by directory and non-directory.
|
||||||
// because of some kind of error.
|
temp_out = std::string(o.infilename) + ".~qpdf-temp#";
|
||||||
temp_out = ".~qpdf-temp." + std::string(o.infilename) + "#";
|
|
||||||
// o.outfilename will be restored to 0 before temp_out
|
// o.outfilename will be restored to 0 before temp_out
|
||||||
// goes out of scope.
|
// goes out of scope.
|
||||||
o.outfilename = temp_out.c_str();
|
o.outfilename = temp_out.c_str();
|
||||||
@ -5180,18 +5179,11 @@ static void write_outfile(QPDF& pdf, Options& o)
|
|||||||
{
|
{
|
||||||
// We must close the input before we can rename files
|
// We must close the input before we can rename files
|
||||||
pdf.closeInputSource();
|
pdf.closeInputSource();
|
||||||
std::string backup;
|
std::string backup = std::string(o.infilename) + ".~qpdf-orig";
|
||||||
bool warnings = pdf.anyWarnings();
|
bool warnings = pdf.anyWarnings();
|
||||||
if (warnings)
|
if (! warnings)
|
||||||
{
|
{
|
||||||
// If there are warnings, the user may care about this
|
backup.append(1, '#');
|
||||||
// file, so give it a non-hidden name that will be
|
|
||||||
// lexically grouped with the original file.
|
|
||||||
backup = std::string(o.infilename) + ".~qpdf-orig";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
backup = ".~qpdf-orig." + std::string(o.infilename) + "#";
|
|
||||||
}
|
}
|
||||||
QUtil::rename_file(o.infilename, backup.c_str());
|
QUtil::rename_file(o.infilename, backup.c_str());
|
||||||
QUtil::rename_file(temp_out.c_str(), o.infilename);
|
QUtil::rename_file(temp_out.c_str(), o.infilename);
|
||||||
|
@ -207,7 +207,7 @@ foreach my $d (['auto-ü', 1], ['auto-öπ', 2])
|
|||||||
my ($u, $n) = @$d;
|
my ($u, $n) = @$d;
|
||||||
$td->runtest("replace input $u",
|
$td->runtest("replace input $u",
|
||||||
{$td->COMMAND => "qpdf --deterministic-id" .
|
{$td->COMMAND => "qpdf --deterministic-id" .
|
||||||
" --object-streams=generate --replace-input $u.pdf"},
|
" --object-streams=generate --replace-input ./$u.pdf"},
|
||||||
{$td->STRING => "", $td->EXIT_STATUS => 0},
|
{$td->STRING => "", $td->EXIT_STATUS => 0},
|
||||||
$td->NORMALIZE_NEWLINES);
|
$td->NORMALIZE_NEWLINES);
|
||||||
$td->runtest("check output ($u)",
|
$td->runtest("check output ($u)",
|
||||||
@ -219,7 +219,7 @@ foreach my $d (['auto-ü', 1], ['auto-öπ', 2])
|
|||||||
system("cp xref-with-short-size.pdf auto-warn.pdf") == 0 or die;
|
system("cp xref-with-short-size.pdf auto-warn.pdf") == 0 or die;
|
||||||
$td->runtest("replace input with warnings",
|
$td->runtest("replace input with warnings",
|
||||||
{$td->COMMAND =>
|
{$td->COMMAND =>
|
||||||
"qpdf --deterministic-id --replace-input auto-warn.pdf"},
|
"qpdf --deterministic-id --replace-input ./auto-warn.pdf"},
|
||||||
{$td->FILE => "replace-warn.out", $td->EXIT_STATUS => 3},
|
{$td->FILE => "replace-warn.out", $td->EXIT_STATUS => 3},
|
||||||
$td->NORMALIZE_NEWLINES);
|
$td->NORMALIZE_NEWLINES);
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
WARNING: auto-warn.pdf (xref stream, offset 16227): Cross-reference stream data has the wrong size; expected = 52; actual = 56
|
WARNING: ./auto-warn.pdf (xref stream, offset 16227): Cross-reference stream data has the wrong size; expected = 52; actual = 56
|
||||||
qpdf: there are warnings; original file kept in auto-warn.pdf.~qpdf-orig
|
qpdf: there are warnings; original file kept in ./auto-warn.pdf.~qpdf-orig
|
||||||
qpdf: operation succeeded with warnings; resulting file may have some problems
|
qpdf: operation succeeded with warnings; resulting file may have some problems
|
||||||
|
Loading…
Reference in New Issue
Block a user