Simplify Movers API and port to FileName.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22119 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-12-13 08:20:45 +00:00
parent 663b5f4417
commit 0186514631
3 changed files with 41 additions and 29 deletions

View File

@ -249,6 +249,21 @@ void ConverterCache::init()
}
static bool changeMode(FileName const & fname, unsigned long int mode)
{
if (mode == (unsigned long int)-1)
return true;
ofstream ofs(fname.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
if (!ofs)
return false;
ofs.close();
if (!chmod(fname, mode))
return false;
return true;
}
void ConverterCache::add(FileName const & orig_from, string const & to_format,
FileName const & converted_file) const
{
@ -289,15 +304,24 @@ void ConverterCache::add(FileName const & orig_from, string const & to_format,
}
item->checksum = checksum;
if (!mover.copy(converted_file, item->cache_name,
onlyFilename(item->cache_name.absFilename()), 0600)) {
LYXERR(Debug::FILES, "ConverterCache::add(" << orig_from << "):\n"
"Could not copy file.");
onlyFilename(item->cache_name.absFilename()))) {
LYXERR(Debug::FILES, "Could not copy file " << orig_from << " to "
<< item->cache_name);
} else if (!changeMode(item->cache_name, 0600)) {
LYXERR(Debug::FILES, "Could not change file mode"
<< item->cache_name);
}
} else {
CacheItem new_item(orig_from, to_format, timestamp,
orig_from.checksum());
// FIXME: The original code used to chmod the new file to 600.
// See SpecialisedMover::do_copy().
if (mover.copy(converted_file, new_item.cache_name,
onlyFilename(new_item.cache_name.absFilename()), 0600)) {
onlyFilename(new_item.cache_name.absFilename()))) {
if (!changeMode(item->cache_name, 0600)) {
LYXERR(Debug::FILES, "Could not change file mode"
<< item->cache_name);
}
FormatCache & format_cache = pimpl_->cache[orig_from];
if (format_cache.from_format.empty())
format_cache.from_format =

View File

@ -26,17 +26,16 @@ using namespace lyx::support;
namespace lyx {
bool Mover::copy(FileName const & from, FileName const & to,
unsigned long int mode) const
bool Mover::copy(FileName const & from, FileName const & to) const
{
return do_copy(from, to, to.absFilename(), mode);
return do_copy(from, to, to.absFilename());
}
bool Mover::do_copy(FileName const & from, FileName const & to,
string const &, unsigned long int mode) const
string const &) const
{
return support::copy(from, to, mode);
return from.copyTo(to);
}
@ -50,24 +49,15 @@ bool Mover::rename(FileName const & from,
bool Mover::do_rename(FileName const & from, FileName const & to,
string const &) const
{
return rename(from, to);
return from.renameTo(to);
}
bool SpecialisedMover::do_copy(FileName const & from, FileName const & to,
string const & latex, unsigned long int mode) const
string const & latex) const
{
if (command_.empty())
return Mover::do_copy(from, to, latex, mode);
if (mode != (unsigned long int)-1) {
ofstream ofs(to.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
if (!ofs)
return false;
ofs.close();
if (!chmod(to, mode))
return false;
}
return Mover::do_copy(from, to, latex);
string command = libScriptSearch(command_);
command = subst(command, "$$i", quoteName(from.toFilesystemEncoding()));
@ -85,7 +75,7 @@ bool SpecialisedMover::do_rename(FileName const & from, FileName const & to,
if (command_.empty())
return Mover::do_rename(from, to, latex);
if (!do_copy(from, to, latex, (unsigned long int)-1))
if (!do_copy(from, to, latex))
return false;
return from.removeFile();
}

View File

@ -36,8 +36,7 @@ public:
* \returns true if successful.
*/
bool
copy(support::FileName const & from, support::FileName const & to,
unsigned long int mode = (unsigned long int)-1) const;
copy(support::FileName const & from, support::FileName const & to) const;
/** Copy file @c from to @c to.
* \see SpecialisedMover::SpecialisedMover() for an explanation of
@ -49,10 +48,9 @@ public:
*/
bool
copy(support::FileName const & from, support::FileName const & to,
std::string const & latex,
unsigned long int mode = (unsigned long int)-1) const
std::string const & latex) const
{
return do_copy(from, to, latex, mode);
return do_copy(from, to, latex);
}
/** Rename file @c from as @c to.
@ -82,7 +80,7 @@ public:
protected:
virtual bool
do_copy(support::FileName const & from, support::FileName const & to,
std::string const &, unsigned long int mode) const;
std::string const &) const;
virtual bool
do_rename(support::FileName const & from, support::FileName const & to,
@ -131,7 +129,7 @@ public:
private:
virtual bool
do_copy(support::FileName const & from, support::FileName const & to,
std::string const & latex, unsigned long int mode) const;
std::string const & latex) const;
virtual bool
do_rename(support::FileName const & from, support::FileName const & to,