]> git.lyx.org Git - lyx.git/blobdiff - src/support/FileMonitor.C
Detect mode_t for safe use of chmod, and for scons/msvc
[lyx.git] / src / support / FileMonitor.C
index 84f47cdaad7fa5fc739491dbb240515fa12716cd..715c10f569fa0b09af421c480b4eecc802224dd8 100644 (file)
@@ -5,26 +5,31 @@
  *
  * \author Angus Leeming
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include "FileMonitor.h"
+#include "support/FileMonitor.h"
+#include "support/lyxlib.h"
 
+// FIXME Interface violation
 #include "frontends/Timeout.h"
 
-#include "support/FileInfo.h"
-#include "support/lyxlib.h"
-
 #include <boost/bind.hpp>
+#include <boost/filesystem/operations.hpp>
 #include <boost/signals/trackable.hpp>
 
-struct FileMonitor::Impl : public boost::signals::trackable {
+
+using std::string;
+
+namespace fs = boost::filesystem;
+
+namespace lyx {
+namespace support {
+
+class FileMonitor::Impl : public boost::signals::trackable {
+public:
 
        ///
        Impl(string const & file_with_path, int interval);
@@ -39,7 +44,7 @@ struct FileMonitor::Impl : public boost::signals::trackable {
        Timeout timer_;
 
        /// This signal is emitted if the file is modified (has a new checksum).
-       boost::signal0<void> fileChanged_;
+       FileMonitor::FileChangedSig fileChanged_;
 
        /** We use these to ascertain whether a file (once loaded successfully)
         *  has changed.
@@ -86,12 +91,11 @@ void FileMonitor::start() const
        if (monitoring())
                return;
 
-       FileInfo finfo(pimpl_->filename_);
-       if (!finfo.isOK())
+       if (!fs::exists(pimpl_->filename_))
                return;
 
-       pimpl_->timestamp_ = finfo.getModificationTime();
-       pimpl_->checksum_ = lyx::sum(pimpl_->filename_);
+       pimpl_->timestamp_ = fs::last_write_time(pimpl_->filename_);
+       pimpl_->checksum_ = sum(pimpl_->filename_);
 
        if (pimpl_->timestamp_ && pimpl_->checksum_) {
                pimpl_->timer_.start();
@@ -121,7 +125,7 @@ unsigned long FileMonitor::checksum() const
        // If we aren't actively monitoring the file, then recompute the
        // checksum explicitly.
        if (!pimpl_->timer_.running() && !pimpl_->filename_.empty())
-               return lyx::sum(pimpl_->filename_);
+               return sum(pimpl_->filename_);
 
        return pimpl_->checksum_;
 }
@@ -152,19 +156,18 @@ void FileMonitor::Impl::monitorFile()
 {
        bool changed = false;
 
-       FileInfo finfo(filename_);
-       if (!finfo.isOK()) {
+       if (!fs::exists(filename_)) {
                changed = timestamp_ || checksum_;
                timestamp_ = 0;
                checksum_ = 0;
 
        } else {
-               time_t const new_timestamp = finfo.getModificationTime();
+               time_t const new_timestamp = fs::last_write_time(filename_);
 
                if (new_timestamp != timestamp_) {
                        timestamp_ = new_timestamp;
 
-                       unsigned long const new_checksum = lyx::sum(filename_);
+                       unsigned long const new_checksum = sum(filename_);
                        if (new_checksum != checksum_) {
                                checksum_ = new_checksum;
                                changed = true;
@@ -176,3 +179,6 @@ void FileMonitor::Impl::monitorFile()
        if (changed)
                fileChanged_();
 }
+
+} // namespace support
+} // namespace lyx