3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
15 #include "support/filetools.h"
16 #include "support/lstrings.h"
17 #include "support/lyxlib.h"
18 #include "support/systemcall.h"
33 bool Mover::copy(support::FileName const & from, support::FileName const & to,
34 unsigned long int mode) const
36 return do_copy(from, to, to.absFilename(), mode);
40 bool Mover::do_copy(support::FileName const & from, support::FileName const & to,
41 string const &, unsigned long int mode) const
43 return support::copy(from, to, mode);
47 bool Mover::rename(support::FileName const & from,
48 support::FileName const & to) const
50 return do_rename(from, to, to.absFilename());
54 bool Mover::do_rename(support::FileName const & from, support::FileName const & to,
57 return support::rename(from, to);
61 bool SpecialisedMover::do_copy(support::FileName const & from, support::FileName const & to,
62 string const & latex, unsigned long int mode) const
65 return Mover::do_copy(from, to, latex, mode);
67 if (mode != (unsigned long int)-1) {
68 std::ofstream ofs(to.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
72 if (!support::chmod(to, mode))
76 string command = support::libScriptSearch(command_);
77 command = support::subst(command, "$$i", from.toFilesystemEncoding());
78 command = support::subst(command, "$$o", to.toFilesystemEncoding());
79 command = support::subst(command, "$$l", latex);
81 support::Systemcall one;
82 return one.startscript(support::Systemcall::Wait, command) == 0;
86 bool SpecialisedMover::do_rename(support::FileName const & from, support::FileName const & to,
87 string const & latex) const
90 return Mover::do_rename(from, to, latex);
92 if (!do_copy(from, to, latex, (unsigned long int)-1))
94 return support::unlink(from) == 0;
98 void Movers::set(string const & fmt, string const & command)
100 specials_[fmt] = SpecialisedMover(command);
104 Mover const & Movers::operator()(string const & fmt) const
106 SpecialsMap::const_iterator const it = specials_.find(fmt);
107 return (it == specials_.end()) ? default_ : it->second;
111 string const Movers::command(string const & fmt) const
113 SpecialsMap::const_iterator const it = specials_.find(fmt);
114 return (it == specials_.end()) ? string() : it->second.command();