Commit e5edfc786f0dab9435379a7420c17695128466b2
1 parent
ee7824cf
QPDFJob: convert infilename to shared pointer
Showing
3 changed files
with
13 additions
and
13 deletions
include/qpdf/QPDFJob.hh
| @@ -309,7 +309,7 @@ class QPDFJob | @@ -309,7 +309,7 @@ class QPDFJob | ||
| 309 | bool replace_input; | 309 | bool replace_input; |
| 310 | bool check_is_encrypted; | 310 | bool check_is_encrypted; |
| 311 | bool check_requires_password; | 311 | bool check_requires_password; |
| 312 | - char const* infilename; | 312 | + std::shared_ptr<char> infilename; |
| 313 | char const* outfilename; | 313 | char const* outfilename; |
| 314 | // QXXXQ END-PUBLIC | 314 | // QXXXQ END-PUBLIC |
| 315 | 315 |
libqpdf/QPDFJob.cc
| @@ -414,7 +414,6 @@ QPDFJob::QPDFJob() : | @@ -414,7 +414,6 @@ QPDFJob::QPDFJob() : | ||
| 414 | replace_input(false), | 414 | replace_input(false), |
| 415 | check_is_encrypted(false), | 415 | check_is_encrypted(false), |
| 416 | check_requires_password(false), | 416 | check_requires_password(false), |
| 417 | - infilename(0), | ||
| 418 | outfilename(0), | 417 | outfilename(0), |
| 419 | m(new Members()) | 418 | m(new Members()) |
| 420 | { | 419 | { |
| @@ -451,7 +450,7 @@ QPDFJob::run() | @@ -451,7 +450,7 @@ QPDFJob::run() | ||
| 451 | std::shared_ptr<QPDF> pdf_ph; | 450 | std::shared_ptr<QPDF> pdf_ph; |
| 452 | try | 451 | try |
| 453 | { | 452 | { |
| 454 | - pdf_ph = processFile(o.infilename, o.password.get()); | 453 | + pdf_ph = processFile(o.infilename.get(), o.password.get()); |
| 455 | } | 454 | } |
| 456 | catch (QPDFExc& e) | 455 | catch (QPDFExc& e) |
| 457 | { | 456 | { |
| @@ -2554,7 +2553,7 @@ QPDFJob::handlePageSpecs( | @@ -2554,7 +2553,7 @@ QPDFJob::handlePageSpecs( | ||
| 2554 | QPDFJob::PageSpec& page_spec = *iter; | 2553 | QPDFJob::PageSpec& page_spec = *iter; |
| 2555 | if (page_spec.filename == ".") | 2554 | if (page_spec.filename == ".") |
| 2556 | { | 2555 | { |
| 2557 | - page_spec.filename = o.infilename; | 2556 | + page_spec.filename = o.infilename.get(); |
| 2558 | } | 2557 | } |
| 2559 | } | 2558 | } |
| 2560 | 2559 | ||
| @@ -2582,7 +2581,7 @@ QPDFJob::handlePageSpecs( | @@ -2582,7 +2581,7 @@ QPDFJob::handlePageSpecs( | ||
| 2582 | // Create a QPDF object for each file that we may take pages from. | 2581 | // Create a QPDF object for each file that we may take pages from. |
| 2583 | std::map<std::string, QPDF*> page_spec_qpdfs; | 2582 | std::map<std::string, QPDF*> page_spec_qpdfs; |
| 2584 | std::map<std::string, ClosedFileInputSource*> page_spec_cfis; | 2583 | std::map<std::string, ClosedFileInputSource*> page_spec_cfis; |
| 2585 | - page_spec_qpdfs[o.infilename] = &pdf; | 2584 | + page_spec_qpdfs[o.infilename.get()] = &pdf; |
| 2586 | std::vector<QPDFPageData> parsed_specs; | 2585 | std::vector<QPDFPageData> parsed_specs; |
| 2587 | std::map<unsigned long long, std::set<QPDFObjGen> > copied_pages; | 2586 | std::map<unsigned long long, std::set<QPDFObjGen> > copied_pages; |
| 2588 | for (std::vector<QPDFJob::PageSpec>::iterator iter = o.page_specs.begin(); | 2587 | for (std::vector<QPDFJob::PageSpec>::iterator iter = o.page_specs.begin(); |
| @@ -3364,7 +3363,7 @@ QPDFJob::doSplitPages(QPDF& pdf, bool& warnings) | @@ -3364,7 +3363,7 @@ QPDFJob::doSplitPages(QPDF& pdf, bool& warnings) | ||
| 3364 | QUtil::uint_to_string(last, QIntC::to_int(pageno_len)); | 3363 | QUtil::uint_to_string(last, QIntC::to_int(pageno_len)); |
| 3365 | } | 3364 | } |
| 3366 | std::string outfile = before + page_range + after; | 3365 | std::string outfile = before + page_range + after; |
| 3367 | - if (QUtil::same_file(o.infilename, outfile.c_str())) | 3366 | + if (QUtil::same_file(o.infilename.get(), outfile.c_str())) |
| 3368 | { | 3367 | { |
| 3369 | throw std::runtime_error( | 3368 | throw std::runtime_error( |
| 3370 | "split pages would overwrite input file with " + outfile); | 3369 | "split pages would overwrite input file with " + outfile); |
| @@ -3392,7 +3391,7 @@ QPDFJob::writeOutfile(QPDF& pdf) | @@ -3392,7 +3391,7 @@ QPDFJob::writeOutfile(QPDF& pdf) | ||
| 3392 | // Append but don't prepend to the path to generate a | 3391 | // Append but don't prepend to the path to generate a |
| 3393 | // temporary name. This saves us from having to split the path | 3392 | // temporary name. This saves us from having to split the path |
| 3394 | // by directory and non-directory. | 3393 | // by directory and non-directory. |
| 3395 | - temp_out = std::string(o.infilename) + ".~qpdf-temp#"; | 3394 | + temp_out = std::string(o.infilename.get()) + ".~qpdf-temp#"; |
| 3396 | // o.outfilename will be restored to 0 before temp_out | 3395 | // o.outfilename will be restored to 0 before temp_out |
| 3397 | // goes out of scope. | 3396 | // goes out of scope. |
| 3398 | o.outfilename = temp_out.c_str(); | 3397 | o.outfilename = temp_out.c_str(); |
| @@ -3421,14 +3420,14 @@ QPDFJob::writeOutfile(QPDF& pdf) | @@ -3421,14 +3420,14 @@ QPDFJob::writeOutfile(QPDF& pdf) | ||
| 3421 | { | 3420 | { |
| 3422 | // We must close the input before we can rename files | 3421 | // We must close the input before we can rename files |
| 3423 | pdf.closeInputSource(); | 3422 | pdf.closeInputSource(); |
| 3424 | - std::string backup = std::string(o.infilename) + ".~qpdf-orig"; | 3423 | + std::string backup = std::string(o.infilename.get()) + ".~qpdf-orig"; |
| 3425 | bool warnings = pdf.anyWarnings(); | 3424 | bool warnings = pdf.anyWarnings(); |
| 3426 | if (! warnings) | 3425 | if (! warnings) |
| 3427 | { | 3426 | { |
| 3428 | backup.append(1, '#'); | 3427 | backup.append(1, '#'); |
| 3429 | } | 3428 | } |
| 3430 | - QUtil::rename_file(o.infilename, backup.c_str()); | ||
| 3431 | - QUtil::rename_file(temp_out.c_str(), o.infilename); | 3429 | + QUtil::rename_file(o.infilename.get(), backup.c_str()); |
| 3430 | + QUtil::rename_file(temp_out.c_str(), o.infilename.get()); | ||
| 3432 | if (warnings) | 3431 | if (warnings) |
| 3433 | { | 3432 | { |
| 3434 | *(this->m->cerr) | 3433 | *(this->m->cerr) |
libqpdf/QPDFJob_argv.cc
| @@ -68,7 +68,7 @@ ArgParser::argPositional(char* arg) | @@ -68,7 +68,7 @@ ArgParser::argPositional(char* arg) | ||
| 68 | { | 68 | { |
| 69 | if (o.infilename == 0) | 69 | if (o.infilename == 0) |
| 70 | { | 70 | { |
| 71 | - o.infilename = arg; | 71 | + o.infilename = QUtil::make_shared_cstr(arg); |
| 72 | } | 72 | } |
| 73 | else if (o.outfilename == 0) | 73 | else if (o.outfilename == 0) |
| 74 | { | 74 | { |
| @@ -211,7 +211,7 @@ ArgParser::argPasswordFile(char* parameter) | @@ -211,7 +211,7 @@ ArgParser::argPasswordFile(char* parameter) | ||
| 211 | void | 211 | void |
| 212 | ArgParser::argEmpty() | 212 | ArgParser::argEmpty() |
| 213 | { | 213 | { |
| 214 | - o.infilename = ""; | 214 | + o.infilename = QUtil::make_shared_cstr(""); |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | void | 217 | void |
| @@ -1513,7 +1513,8 @@ ArgParser::doFinalChecks() | @@ -1513,7 +1513,8 @@ ArgParser::doFinalChecks() | ||
| 1513 | } | 1513 | } |
| 1514 | } | 1514 | } |
| 1515 | 1515 | ||
| 1516 | - if ((! o.split_pages) && QUtil::same_file(o.infilename, o.outfilename)) | 1516 | + if ((! o.split_pages) && |
| 1517 | + QUtil::same_file(o.infilename.get(), o.outfilename)) | ||
| 1517 | { | 1518 | { |
| 1518 | QTC::TC("qpdf", "qpdf same file error"); | 1519 | QTC::TC("qpdf", "qpdf same file error"); |
| 1519 | usage("input file and output file are the same;" | 1520 | usage("input file and output file are the same;" |