+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
{
void ConverterCache::add(FileName const & orig_from, string const & to_format,
FileName const & converted_file) const
{
}
item->checksum = checksum;
if (!mover.copy(converted_file, item->cache_name,
}
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());
}
} 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,
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 =
FormatCache & format_cache = pimpl_->cache[orig_from];
if (format_cache.from_format.empty())
format_cache.from_format =
-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,
}
bool Mover::do_copy(FileName const & from, FileName const & to,
- string const &, unsigned long int mode) const
- return support::copy(from, to, mode);
+ return from.copyTo(to);
bool Mover::do_rename(FileName const & from, FileName const & to,
string const &) const
{
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,
}
bool SpecialisedMover::do_copy(FileName const & from, FileName const & to,
- string const & latex, unsigned long int mode) const
+ string const & latex) const
- 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()));
string command = libScriptSearch(command_);
command = subst(command, "$$i", quoteName(from.toFilesystemEncoding()));
if (command_.empty())
return Mover::do_rename(from, to, latex);
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();
}
return false;
return from.removeFile();
}
* \returns true if successful.
*/
bool
* \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
/** Copy file @c from to @c to.
* \see SpecialisedMover::SpecialisedMover() for an explanation of
*/
bool
copy(support::FileName const & from, support::FileName const & to,
*/
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.
}
/** Rename file @c from as @c to.
protected:
virtual bool
do_copy(support::FileName const & from, support::FileName const & to,
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,
virtual bool
do_rename(support::FileName const & from, support::FileName const & to,
private:
virtual bool
do_copy(support::FileName const & from, support::FileName const & to,
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,
virtual bool
do_rename(support::FileName const & from, support::FileName const & to,