Mercurial > hg > easyhg
comparison src/fswatcher.cpp @ 541:0a16db274f2c fswatcher
Update the filesystem watcher with work directory / file state. Still doesn't track "clean" files properly unless "show all files" is enabled
author | Chris Cannam |
---|---|
date | Tue, 14 Feb 2012 16:17:23 +0000 |
parents | fc2df97920e8 |
children | 7829da6abe97 |
comparison
equal
deleted
inserted
replaced
540:fc2df97920e8 | 541:0a16db274f2c |
---|---|
63 | 63 |
64 void | 64 void |
65 FsWatcher::setWorkDirPath(QString path) | 65 FsWatcher::setWorkDirPath(QString path) |
66 { | 66 { |
67 QMutexLocker locker(&m_mutex); | 67 QMutexLocker locker(&m_mutex); |
68 if (m_workDirPath == path) return; | |
68 m_watcher.removePaths(m_watcher.directories()); | 69 m_watcher.removePaths(m_watcher.directories()); |
69 m_watcher.removePaths(m_watcher.files()); | 70 m_watcher.removePaths(m_watcher.files()); |
70 m_workDirPath = path; | 71 m_workDirPath = path; |
71 addWorkDirectory(path); | 72 addWorkDirectory(path); |
72 debugPrint(); | 73 debugPrint(); |
74 | 75 |
75 void | 76 void |
76 FsWatcher::setTrackedFilePaths(QStringList paths) | 77 FsWatcher::setTrackedFilePaths(QStringList paths) |
77 { | 78 { |
78 QMutexLocker locker(&m_mutex); | 79 QMutexLocker locker(&m_mutex); |
79 m_watcher.removePaths(m_watcher.files()); | 80 |
81 QSet<QString> alreadyWatched = | |
82 QSet<QString>::fromList(m_watcher.files()); | |
83 | |
80 foreach (QString path, paths) { | 84 foreach (QString path, paths) { |
81 m_watcher.addPath(path); | 85 if (!alreadyWatched.contains(path)) { |
82 } | 86 m_watcher.addPath(path); |
87 } else { | |
88 alreadyWatched.remove(path); | |
89 } | |
90 } | |
91 | |
92 // Remove the remaining paths, those that were being watched | |
93 // before but that are not in the list we were given | |
94 foreach (QString path, alreadyWatched) { | |
95 m_watcher.removePath(path); | |
96 } | |
97 | |
83 debugPrint(); | 98 debugPrint(); |
84 } | 99 } |
85 | 100 |
86 void | 101 void |
87 FsWatcher::addWorkDirectory(QString path) | 102 FsWatcher::addWorkDirectory(QString path) |
169 if (files == m_dirContents[path]) { | 184 if (files == m_dirContents[path]) { |
170 #ifdef DEBUG_FSWATCHER | 185 #ifdef DEBUG_FSWATCHER |
171 std::cerr << "FsWatcher: Directory " << path << " has changed, but not in a way that we are monitoring" << std::endl; | 186 std::cerr << "FsWatcher: Directory " << path << " has changed, but not in a way that we are monitoring" << std::endl; |
172 #endif | 187 #endif |
173 return; | 188 return; |
174 } | 189 } else { |
175 else m_dirContents[path] = files; | 190 #ifdef DEBUG_FSWATCHER |
191 std::cerr << "FsWatcher: Directory " << path << " has changed" << std::endl; | |
192 #endif | |
193 m_dirContents[path] = files; | |
194 } | |
176 | 195 |
177 size_t counter = ++m_lastCounter; | 196 size_t counter = ++m_lastCounter; |
178 m_changes[path] = counter; | 197 m_changes[path] = counter; |
179 } | 198 } |
180 | 199 |
190 // We don't check whether the file matches an ignore pattern, | 209 // We don't check whether the file matches an ignore pattern, |
191 // because we are only notified for file changes if we are | 210 // because we are only notified for file changes if we are |
192 // watching the file explicitly, i.e. the file is in the | 211 // watching the file explicitly, i.e. the file is in the |
193 // tracked file paths list. So we never want to ignore them | 212 // tracked file paths list. So we never want to ignore them |
194 | 213 |
214 std::cerr << "FsWatcher: Tracked file " << path << " has changed" << std::endl; | |
215 | |
195 size_t counter = ++m_lastCounter; | 216 size_t counter = ++m_lastCounter; |
196 m_changes[path] = counter; | 217 m_changes[path] = counter; |
197 } | 218 } |
198 | 219 |
199 emit changed(); | 220 emit changed(); |
203 FsWatcher::shouldIgnore(QString path) | 224 FsWatcher::shouldIgnore(QString path) |
204 { | 225 { |
205 QFileInfo fi(path); | 226 QFileInfo fi(path); |
206 QString fn(fi.fileName()); | 227 QString fn(fi.fileName()); |
207 foreach (QString pfx, m_ignoredPrefixes) { | 228 foreach (QString pfx, m_ignoredPrefixes) { |
208 if (fn.startsWith(pfx)) return true; | 229 if (fn.startsWith(pfx)) { |
230 std::cerr << "(ignoring: " << path << ")" << std::endl; | |
231 return true; | |
232 } | |
209 } | 233 } |
210 foreach (QString sfx, m_ignoredSuffixes) { | 234 foreach (QString sfx, m_ignoredSuffixes) { |
211 if (fn.endsWith(sfx)) return true; | 235 if (fn.endsWith(sfx)) { |
236 std::cerr << "(ignoring: " << path << ")" << std::endl; | |
237 return true; | |
238 } | |
212 } | 239 } |
213 return false; | 240 return false; |
214 } | 241 } |
215 | 242 |
216 QSet<QString> | 243 QSet<QString> |
225 if (entry.startsWith('.')) continue; | 252 if (entry.startsWith('.')) continue; |
226 if (shouldIgnore(entry)) continue; | 253 if (shouldIgnore(entry)) continue; |
227 files.insert(entry); | 254 files.insert(entry); |
228 } | 255 } |
229 } | 256 } |
257 // std::cerr << "scanDirectory:" << std::endl; | |
258 // foreach (QString f, files) std::cerr << f << std::endl; | |
230 return files; | 259 return files; |
231 } | 260 } |
232 | 261 |
233 void | 262 void |
234 FsWatcher::debugPrint() | 263 FsWatcher::debugPrint() |