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"
24 using namespace lyx::support;
29 bool Mover::copy(support::FileName const & from, support::FileName const & to,
30 unsigned long int mode) const
32 return do_copy(from, to, to.absFilename(), mode);
36 bool Mover::do_copy(support::FileName const & from, support::FileName const & to,
37 string const &, unsigned long int mode) const
39 return support::copy(from, to, mode);
43 bool Mover::rename(support::FileName const & from,
44 support::FileName const & to) const
46 return do_rename(from, to, to.absFilename());
50 bool Mover::do_rename(support::FileName const & from, support::FileName const & to,
53 return support::rename(from, to);
57 bool SpecialisedMover::do_copy(support::FileName const & from, support::FileName const & to,
58 string const & latex, unsigned long int mode) const
61 return Mover::do_copy(from, to, latex, mode);
63 if (mode != (unsigned long int)-1) {
64 std::ofstream ofs(to.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
68 if (!support::chmod(to, mode))
72 string command = support::libScriptSearch(command_);
73 command = support::subst(command, "$$i", quoteName(from.toFilesystemEncoding()));
74 command = support::subst(command, "$$o", quoteName(to.toFilesystemEncoding()));
75 command = support::subst(command, "$$l", quoteName(latex));
77 support::Systemcall one;
78 return one.startscript(support::Systemcall::Wait, command) == 0;
82 bool SpecialisedMover::do_rename(support::FileName const & from, support::FileName const & to,
83 string const & latex) const
86 return Mover::do_rename(from, to, latex);
88 if (!do_copy(from, to, latex, (unsigned long int)-1))
90 return from.removeFile();
94 void Movers::set(string const & fmt, string const & command)
96 specials_[fmt] = SpecialisedMover(command);
100 Mover const & Movers::operator()(string const & fmt) const
102 SpecialsMap::const_iterator const it = specials_.find(fmt);
103 if (it == specials_.end())
109 string const Movers::command(string const & fmt) const
111 SpecialsMap::const_iterator const it = specials_.find(fmt);
112 return (it == specials_.end()) ? string() : it->second.command();