diff --git a/src/ConverterCache.cpp b/src/ConverterCache.cpp index 14dce2d539..96efb0ffb0 100644 --- a/src/ConverterCache.cpp +++ b/src/ConverterCache.cpp @@ -249,21 +249,6 @@ 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 { @@ -307,7 +292,7 @@ void ConverterCache::add(FileName const & orig_from, string const & to_format, 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)) { + } else if (!item->cache_name.changeMode(0600)) { LYXERR(Debug::FILES, "Could not change file mode" << item->cache_name); } @@ -316,7 +301,7 @@ void ConverterCache::add(FileName const & orig_from, string const & to_format, orig_from.checksum()); if (mover.copy(converted_file, new_item.cache_name, onlyFilename(new_item.cache_name.absFilename()))) { - if (!changeMode(new_item.cache_name, 0600)) { + if (!new_item.cache_name.changeMode(0600)) { LYXERR(Debug::FILES, "Could not change file mode" << new_item.cache_name); } diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp index 92d411820c..63f13e2325 100644 --- a/src/support/FileName.cpp +++ b/src/support/FileName.cpp @@ -60,7 +60,9 @@ struct FileName::Private Private() {} Private(string const & abs_filename) : fi(toqstr(abs_filename)) - {} + { + fi.setCaching(fi.exists() ? true : false); + } /// QFileInfo fi; }; @@ -148,6 +150,21 @@ bool FileName::renameTo(FileName const & name) const } +bool FileName::changePermission(unsigned long int mode) const +{ + if (!fname.isWritable()) { + LYXERR0("File " << *this << " is not writable!"); + return false; + } + + if (!chmod(fname, mode)) { + LYXERR0("File " << *this << " cannot be changed to " << mode << " mode!"); + return false; + } + return true; +} + + string FileName::toFilesystemEncoding() const { QByteArray const encoded = QFile::encodeName(d->fi.absoluteFilePath()); diff --git a/src/support/FileName.h b/src/support/FileName.h index 328602bf34..b74ca1bf17 100644 --- a/src/support/FileName.h +++ b/src/support/FileName.h @@ -102,6 +102,9 @@ public: /// \retrun true on success. bool renameTo(FileName const & target) const; + /// change mode of pointed file. + /// \retrun true on success. + bool changeMode(unsigned long int mode) const; /// remove directory and all contents, returns true on success bool destroyDirectory() const;