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"
28 bool Mover::copy(support::FileName const & from, support::FileName const & to,
29 unsigned long int mode) const
31 return do_copy(from, to, to.absFilename(), mode);
35 bool Mover::do_copy(support::FileName const & from, support::FileName const & to,
36 string const &, unsigned long int mode) const
38 return support::copy(from, to, mode);
42 bool Mover::rename(support::FileName const & from,
43 support::FileName const & to) const
45 return do_rename(from, to, to.absFilename());
49 bool Mover::do_rename(support::FileName const & from, support::FileName const & to,
52 return support::rename(from, to);
56 bool SpecialisedMover::do_copy(support::FileName const & from, support::FileName const & to,
57 string const & latex, unsigned long int mode) const
60 return Mover::do_copy(from, to, latex, mode);
62 if (mode != (unsigned long int)-1) {
63 std::ofstream ofs(to.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
67 if (!support::chmod(to, mode))
71 string command = support::libScriptSearch(command_);
72 command = support::subst(command, "$$i", from.toFilesystemEncoding());
73 command = support::subst(command, "$$o", to.toFilesystemEncoding());
74 command = support::subst(command, "$$l", latex);
76 support::Systemcall one;
77 return one.startscript(support::Systemcall::Wait, command) == 0;
81 bool SpecialisedMover::do_rename(support::FileName const & from, support::FileName const & to,
82 string const & latex) const
85 return Mover::do_rename(from, to, latex);
87 if (!do_copy(from, to, latex, (unsigned long int)-1))
89 return support::unlink(from) == 0;
93 void Movers::set(string const & fmt, string const & command)
95 specials_[fmt] = SpecialisedMover(command);
99 Mover const & Movers::operator()(string const & fmt) const
101 SpecialsMap::const_iterator const it = specials_.find(fmt);
102 if (it == specials_.end())
108 string const Movers::command(string const & fmt) const
110 SpecialsMap::const_iterator const it = specials_.find(fmt);
111 return (it == specials_.end()) ? string() : it->second.command();