Something like that?
Index: Buffer.h =================================================================== --- Buffer.h (revision 21005) +++ Buffer.h (working copy) @@ -212,7 +212,7 @@ bool isExternallyModified(CheckMethod method) const; /// save timestamp and checksum of the given file. - void saveCheckSum(std::string const & file) const; + void saveCheckSum(FileName const & file) const; /// mark the main lyx file as not needing saving void markClean() const; Index: support/FileName.cpp =================================================================== --- support/FileName.cpp (revision 21005) +++ support/FileName.cpp (working copy) @@ -17,8 +17,10 @@ #include "support/qstring_helpers.h" #include <QFile> +#include <QFileInfo> -#include <boost/assert.hpp> +#include <boost/filesystem/exception.hpp> +#include <boost/filesystem/operations.hpp> #include <map> #include <sstream> @@ -28,19 +30,17 @@ using std::map; using std::string; - namespace lyx { namespace support { -FileName::FileName() -{} +///////////////////////////////////////////////////////////////////// +// +// FileName +// +///////////////////////////////////////////////////////////////////// -FileName::~FileName() -{} - - FileName::FileName(string const & abs_filename) : name_(abs_filename) { @@ -81,6 +81,25 @@ } +bool FileName::exists() const +{ + return QFileInfo(toqstr(name_)).exists(); +} + + +bool FileName::isReadOnly() const +{ + QFileInfo const fi(toqstr(name_)); + return fi.isReadable() && !fi.isWritable(); +} + + +std::time_t FileName::lastModified() const +{ + return boost::filesystem::last_write_time(toFilesystemEncoding()); +} + + bool operator==(FileName const & lhs, FileName const & rhs) { return lhs.absFilename() == rhs.absFilename(); @@ -111,6 +130,13 @@ } +///////////////////////////////////////////////////////////////////// +// +// DocFileName +// +///////////////////////////////////////////////////////////////////// + + DocFileName::DocFileName() : save_abs_path_(true) {} Index: support/FileName.h =================================================================== --- support/FileName.h (revision 21005) +++ support/FileName.h (working copy) @@ -27,7 +27,7 @@ class FileName { public: /// Constructor for empty filenames - FileName(); + FileName() {} /** Constructor for nonempty filenames. * explicit because we don't want implicit conversion of relative * paths in function arguments (e.g. of unlink). @@ -35,7 +35,7 @@ * Encoding is always UTF-8. */ explicit FileName(std::string const & abs_filename); - virtual ~FileName(); + virtual ~FileName() {} /** Set a new filename. * \param filename the file in question. Must have an absolute path. * Encoding is always UTF-8. @@ -51,6 +51,14 @@ * Only use this for accessing the file, e.g. with an fstream. */ std::string const toFilesystemEncoding() const; + + /// returns true if the file exists + bool exists() const; + /// returns time of last write access + std::time_t lastModified() const; + /// return true when file is readable but not writabel + bool isReadOnly() const; + /** * Get a FileName from \p name in the encoding used by the file system. * Only use this for filenames you got directly from the file system, @@ -102,7 +110,7 @@ std::string const relFilename(std::string const & buffer_path = std::string()) const; /// \param buf_path if empty, uses `pwd` std::string const outputFilename(std::string const & buf_path = std::string()) const; - + /** @returns a mangled representation of the absolute file name * suitable for use in the temp dir when, for example, converting * an image file to another format. Index: Buffer.cpp =================================================================== --- Buffer.cpp (revision 21005) +++ Buffer.cpp (working copy) @@ -432,9 +432,8 @@ // If no Latex log or Build log is newer, show Build log - if (fs::exists(bname.toFilesystemEncoding()) && - (!fs::exists(fname.toFilesystemEncoding()) || - fs::last_write_time(fname.toFilesystemEncoding()) < fs::last_write_time(bname.toFilesystemEncoding()))) { + if (bname.exists() && + (!fname.exists() || fname.lastModified() < bname.lastModified())) { LYXERR(Debug::FILES) << "Log name calculated as: " << bname << endl; return make_pair(Buffer::buildlog, bname.absFilename()); } @@ -456,7 +455,7 @@ { pimpl_->filename = makeAbsPath(newfile); params().filepath = onlyPath(pimpl_->filename.absFilename()); - setReadonly(fs::is_readonly(pimpl_->filename.toFilesystemEncoding())); + setReadonly(pimpl_->filename.isReadOnly()); updateTitles(); } @@ -704,7 +703,7 @@ // FileName lyxfile(addName(temppath(), "content.lyx")); // if both manifest.txt and file.lyx exist, this is am embedded file - if (fs::exists(lyxfile.toFilesystemEncoding())) { + if (lyxfile.exists()) { params().embedded = true; fname = lyxfile; } @@ -750,7 +749,7 @@ } lex.next(); - string const token(lex.getString()); + string const token = lex.getString(); if (!lex) { Alert::error(_("Document could not be read"), @@ -874,7 +873,7 @@ bool madeBackup = false; // make a backup if the file already exists - if (lyxrc.make_backup && fs::exists(encodedFilename)) { + if (lyxrc.make_backup && pimpl_->filename.exists()) { backupName = FileName(fileName() + '~'); if (!lyxrc.backupdir_path.empty()) backupName = FileName(addName(lyxrc.backupdir_path, @@ -1661,19 +1660,19 @@ bool Buffer::isExternallyModified(CheckMethod method) const { - BOOST_ASSERT(fs::exists(pimpl_->filename.toFilesystemEncoding())); + BOOST_ASSERT(pimpl_->filename.exists()); // if method == timestamp, check timestamp before checksum return (method == checksum_method - || pimpl_->timestamp_ != fs::last_write_time(pimpl_->filename.toFilesystemEncoding())) + || pimpl_->timestamp_ != pimpl_->filename.lastModified())) && pimpl_->checksum_ != sum(pimpl_->filename); } -void Buffer::saveCheckSum(string const & file) const +void Buffer::saveCheckSum(FileName const & file) const { - if (fs::exists(file)) { - pimpl_->timestamp_ = fs::last_write_time(file); - pimpl_->checksum_ = sum(FileName(file)); + if (file.exists()) { + pimpl_->timestamp_ = file.lastModified(); + pimpl_->checksum_ = sum(file); } else { // in the case of save to a new file. pimpl_->timestamp_ = 0; @@ -2152,7 +2151,7 @@ } else fname = makeAbsPath(newname, onlyPath(oldname)).absFilename(); - if (fs::exists(FileName(fname).toFilesystemEncoding())) { + if (FileName(fname).exists) { docstring const file = makeDisplayPath(fname, 30); docstring text = bformat(_("The document %1$s already " "exists.\n\nDo you want to "