diff src/fswatcher.cpp @ 539:3935a7e621ca fswatcher

Add setTrackedFilePaths, and comments
author Chris Cannam
date Fri, 10 Feb 2012 21:49:27 +0000
parents bdc9de794839
children fc2df97920e8
line wrap: on
line diff
--- a/src/fswatcher.cpp	Fri Feb 10 17:53:04 2012 +0000
+++ b/src/fswatcher.cpp	Fri Feb 10 21:49:27 2012 +0000
@@ -22,6 +22,25 @@
 
 #include <deque>
 
+/*
+ * Watching the filesystem is trickier than it seems at first glance.
+ *
+ * We ideally should watch every directory, and every file that is
+ * tracked by Hg. If a new file is created in a directory, then we
+ * need to respond in order to show it as a potential candidate to be
+ * added.
+ *
+ * Complicating matters though is that Hg itself might modify the
+ * filesystem. This can happen even in "read-only" operations: for
+ * example, hg stat creates files called hg-checklink and hg-checkexec
+ * to test properties of the filesystem. So we need to know to ignore
+ * those files; unfortunately, when watching a directory (which is how
+ * we find out about the creation of new files) we are notified only
+ * that the directory has changed -- we aren't told what changed. So
+ * we need to rescan the directory merely to find out whether to
+ * ignore the change or not.
+ */
+
 FsWatcher::FsWatcher() :
     m_lastToken(0),
     m_lastCounter(0)
@@ -47,6 +66,16 @@
 }
 
 void
+FsWatcher::setTrackedFilePaths(QStringList paths)
+{
+    QMutexLocker locker(&m_mutex);
+    m_watcher.removePaths(m_watcher.files());
+    foreach (QString path, paths) {
+	m_watcher.addPath(path);
+    }
+}
+
+void
 FsWatcher::addWorkDirectory(QString path)
 {
     // QFileSystemWatcher will refuse to add a file or directory to