X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmover.C;h=6fb9daf06c5cd988505ce81f0c0493d229c43068;hb=52eb91c94fb70d58dceef430659c8781de2eccda;hp=a646f49478ce8d28923a131fceec26d398d4fcb9;hpb=e5706b107da902bc6a28cba0de3ccd6f75d9fee7;p=lyx.git diff --git a/src/mover.C b/src/mover.C index a646f49478..6fb9daf06c 100644 --- a/src/mover.C +++ b/src/mover.C @@ -8,6 +8,8 @@ * Full author contact details are available in file CREDITS. */ +#include + #include "mover.h" #include "support/filetools.h" @@ -15,49 +17,76 @@ #include "support/lyxlib.h" #include "support/systemcall.h" +#include #include -using std::ostringstream; +using std::ios; using std::string; -namespace support = lyx::support; +namespace lyx { + +using support::quoteName; -Movers movers; -Movers system_movers; +bool Mover::copy(support::FileName const & from, support::FileName const & to, + unsigned long int mode) const +{ + return do_copy(from, to, to.absFilename(), mode); +} -bool Mover::do_copy(string const & from, string const & to) const +bool Mover::do_copy(support::FileName const & from, support::FileName const & to, + string const &, unsigned long int mode) const { - return support::copy(from, to); + return support::copy(from, to, mode); } -bool Mover::do_rename(string const & from, string const & to) const +bool Mover::rename(support::FileName const & from, + support::FileName const & to) const +{ + return do_rename(from, to, to.absFilename()); +} + + +bool Mover::do_rename(support::FileName const & from, support::FileName const & to, + string const &) const { return support::rename(from, to); } -bool SpecialisedMover::do_copy(string const & from, string const & to) const +bool SpecialisedMover::do_copy(support::FileName const & from, support::FileName const & to, + string const & latex, unsigned long int mode) const { if (command_.empty()) - return Mover::do_copy(from, to); - - string command = support::LibScriptSearch(command_); - command = support::subst(command, "$$i", from); - command = support::subst(command, "$$o", to); + return Mover::do_copy(from, to, latex, mode); + + if (mode != (unsigned long int)-1) { + std::ofstream ofs(to.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc); + if (!ofs) + return false; + ofs.close(); + if (!support::chmod(to, mode)) + return false; + } + + string command = support::libScriptSearch(command_); + command = support::subst(command, "$$i", quoteName(from.toFilesystemEncoding())); + command = support::subst(command, "$$o", quoteName(to.toFilesystemEncoding())); + command = support::subst(command, "$$l", quoteName(latex)); support::Systemcall one; return one.startscript(support::Systemcall::Wait, command) == 0; } -bool SpecialisedMover::do_rename(string const & from, string const & to) const +bool SpecialisedMover::do_rename(support::FileName const & from, support::FileName const & to, + string const & latex) const { if (command_.empty()) - return Mover::do_rename(from, to); + return Mover::do_rename(from, to, latex); - if (!do_copy(from, to)) + if (!do_copy(from, to, latex, (unsigned long int)-1)) return false; return support::unlink(from) == 0; } @@ -72,7 +101,9 @@ void Movers::set(string const & fmt, string const & command) Mover const & Movers::operator()(string const & fmt) const { SpecialsMap::const_iterator const it = specials_.find(fmt); - return (it == specials_.end()) ? default_ : it->second; + if (it == specials_.end()) + return default_; + return it->second; } @@ -81,3 +112,6 @@ string const Movers::command(string const & fmt) const SpecialsMap::const_iterator const it = specials_.find(fmt); return (it == specials_.end()) ? string() : it->second.command(); } + + +} // namespace lyx