comparison 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
comparison
equal deleted inserted replaced
538:bdc9de794839 539:3935a7e621ca
20 #include <QMutexLocker> 20 #include <QMutexLocker>
21 #include <QDir> 21 #include <QDir>
22 22
23 #include <deque> 23 #include <deque>
24 24
25 /*
26 * Watching the filesystem is trickier than it seems at first glance.
27 *
28 * We ideally should watch every directory, and every file that is
29 * tracked by Hg. If a new file is created in a directory, then we
30 * need to respond in order to show it as a potential candidate to be
31 * added.
32 *
33 * Complicating matters though is that Hg itself might modify the
34 * filesystem. This can happen even in "read-only" operations: for
35 * example, hg stat creates files called hg-checklink and hg-checkexec
36 * to test properties of the filesystem. So we need to know to ignore
37 * those files; unfortunately, when watching a directory (which is how
38 * we find out about the creation of new files) we are notified only
39 * that the directory has changed -- we aren't told what changed. So
40 * we need to rescan the directory merely to find out whether to
41 * ignore the change or not.
42 */
43
25 FsWatcher::FsWatcher() : 44 FsWatcher::FsWatcher() :
26 m_lastToken(0), 45 m_lastToken(0),
27 m_lastCounter(0) 46 m_lastCounter(0)
28 { 47 {
29 connect(&m_watcher, SIGNAL(directoryChanged(QString)), 48 connect(&m_watcher, SIGNAL(directoryChanged(QString)),
42 QMutexLocker locker(&m_mutex); 61 QMutexLocker locker(&m_mutex);
43 m_watcher.removePaths(m_watcher.directories()); 62 m_watcher.removePaths(m_watcher.directories());
44 m_watcher.removePaths(m_watcher.files()); 63 m_watcher.removePaths(m_watcher.files());
45 m_workDirPath = path; 64 m_workDirPath = path;
46 addWorkDirectory(path); 65 addWorkDirectory(path);
66 }
67
68 void
69 FsWatcher::setTrackedFilePaths(QStringList paths)
70 {
71 QMutexLocker locker(&m_mutex);
72 m_watcher.removePaths(m_watcher.files());
73 foreach (QString path, paths) {
74 m_watcher.addPath(path);
75 }
47 } 76 }
48 77
49 void 78 void
50 FsWatcher::addWorkDirectory(QString path) 79 FsWatcher::addWorkDirectory(QString path)
51 { 80 {