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 using support::quoteName
;
30 bool Mover::copy(support::FileName
const & from
, support::FileName
const & to
,
31 unsigned long int mode
) const
33 return do_copy(from
, to
, to
.absFilename(), mode
);
37 bool Mover::do_copy(support::FileName
const & from
, support::FileName
const & to
,
38 string
const &, unsigned long int mode
) const
40 return support::copy(from
, to
, mode
);
44 bool Mover::rename(support::FileName
const & from
,
45 support::FileName
const & to
) const
47 return do_rename(from
, to
, to
.absFilename());
51 bool Mover::do_rename(support::FileName
const & from
, support::FileName
const & to
,
54 return support::rename(from
, to
);
58 bool SpecialisedMover::do_copy(support::FileName
const & from
, support::FileName
const & to
,
59 string
const & latex
, unsigned long int mode
) const
62 return Mover::do_copy(from
, to
, latex
, mode
);
64 if (mode
!= (unsigned long int)-1) {
65 std::ofstream
ofs(to
.toFilesystemEncoding().c_str(), ios::binary
| ios::out
| ios::trunc
);
69 if (!support::chmod(to
, mode
))
73 string command
= support::libScriptSearch(command_
);
74 command
= support::subst(command
, "$$i", quoteName(from
.toFilesystemEncoding()));
75 command
= support::subst(command
, "$$o", quoteName(to
.toFilesystemEncoding()));
76 command
= support::subst(command
, "$$l", quoteName(latex
));
78 support::Systemcall one
;
79 return one
.startscript(support::Systemcall::Wait
, command
) == 0;
83 bool SpecialisedMover::do_rename(support::FileName
const & from
, support::FileName
const & to
,
84 string
const & latex
) const
87 return Mover::do_rename(from
, to
, latex
);
89 if (!do_copy(from
, to
, latex
, (unsigned long int)-1))
91 return support::unlink(from
) == 0;
95 void Movers::set(string
const & fmt
, string
const & command
)
97 specials_
[fmt
] = SpecialisedMover(command
);
101 Mover
const & Movers::operator()(string
const & fmt
) const
103 SpecialsMap::const_iterator
const it
= specials_
.find(fmt
);
104 if (it
== specials_
.end())
110 string
const Movers::command(string
const & fmt
) const
112 SpecialsMap::const_iterator
const it
= specials_
.find(fmt
);
113 return (it
== specials_
.end()) ? string() : it
->second
.command();