comparison src/fswatcher.cpp @ 593:40b40c193eaa

Fix file update time calculation in FS watcher
author Chris Cannam
date Tue, 17 Apr 2012 13:31:30 +0100
parents 0b0444762a5d
children 10ef94e51f44
comparison
equal deleted inserted replaced
592:0b0444762a5d 593:40b40c193eaa
26 #include "fswatcher.h" 26 #include "fswatcher.h"
27 #include "debug.h" 27 #include "debug.h"
28 28
29 #include <deque> 29 #include <deque>
30 30
31 //#define DEBUG_FSWATCHER 1 31 #define DEBUG_FSWATCHER 1
32 32
33 /* 33 /*
34 * Watching the filesystem is trickier than it seems at first glance. 34 * Watching the filesystem is trickier than it seems at first glance.
35 * 35 *
36 * We ideally should watch every directory, and every file that is 36 * We ideally should watch every directory, and every file that is
295 { 295 {
296 QMutexLocker locker(&m_mutex); 296 QMutexLocker locker(&m_mutex);
297 size_t lastUpdatedAt = m_tokenMap[token]; 297 size_t lastUpdatedAt = m_tokenMap[token];
298 QSet<QString> changed; 298 QSet<QString> changed;
299 for (QHash<QString, size_t>::const_iterator i = m_changes.begin(); 299 for (QHash<QString, size_t>::const_iterator i = m_changes.begin();
300 i != m_changes.end(); ++i) { 300 i != m_changes.end(); ++i) {
301 if (i.value() > lastUpdatedAt) { 301 if (i.value() > lastUpdatedAt) {
302 changed.insert(i.key()); 302 changed.insert(i.key());
303 } 303 }
304 } 304 }
305 m_tokenMap[token] = m_lastCounter; 305 m_tokenMap[token] = m_lastCounter;
306 return changed; 306 return changed;
307 } 307 }
308 308
319 QSet<QString> files = scanDirectory(path); 319 QSet<QString> files = scanDirectory(path);
320 320
321 if (files == m_dirContents[path]) { 321 if (files == m_dirContents[path]) {
322 322
323 #ifdef DEBUG_FSWATCHER 323 #ifdef DEBUG_FSWATCHER
324 std::cerr << "FsWatcher: Directory " << path << " has changed, but not in a way that we are monitoring" << std::endl; 324 std::cerr << "FsWatcher: Directory " << path << " has changed, but not in a way that we are monitoring -- doing manual check" << std::endl;
325 #endif 325 #endif
326 326
327 #ifdef Q_OS_MAC 327 #ifdef Q_OS_MAC
328 haveChanges = manuallyCheckTrackedFiles(); 328 haveChanges = manuallyCheckTrackedFiles();
329 #endif 329 #endif
369 369
370 #ifdef Q_OS_MAC 370 #ifdef Q_OS_MAC
371 bool 371 bool
372 FsWatcher::manuallyCheckTrackedFiles() 372 FsWatcher::manuallyCheckTrackedFiles()
373 { 373 {
374 std::cerr << "FsWatcher::manuallyCheckTrackedFiles" << std::endl;
374 bool foundChanges = false; 375 bool foundChanges = false;
375 376
376 for (PathTimeMap::iterator i = m_trackedFileUpdates.begin(); 377 for (PathTimeMap::iterator i = m_trackedFileUpdates.begin();
377 i != m_trackedFileUpdates.end(); ++i) { 378 i != m_trackedFileUpdates.end(); ++i) {
378 379
379 QString path = i.key(); 380 QString path = i.key();
380 QDateTime prevUpdate = i.value(); 381 QDateTime prevUpdate = i.value();
381 382
382 QFileInfo fi(path); 383 QFileInfo fi(m_workDirPath + QDir::separator() + path);
383 QDateTime currUpdate = fi.lastModified(); 384 QDateTime currUpdate = fi.lastModified();
385
386 // std::cerr << "FsWatcher: Tracked file " << path << " previously changed at "
387 // << prevUpdate.toString().toStdString()
388 // << ", currently at " << currUpdate.toString().toStdString() << std::endl;
384 389
385 if (currUpdate > prevUpdate) { 390 if (currUpdate > prevUpdate) {
386 391
387 #ifdef DEBUG_FSWATCHER 392 #ifdef DEBUG_FSWATCHER
388 std::cerr << "FsWatcher: Tracked file " << path << " has been changed since last check" << std::endl; 393 std::cerr << "FsWatcher: Tracked file " << path << " has been changed since last check" << std::endl;