diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2013-07-27 16:40:52 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2013-07-27 16:40:52 +0200 |
commit | 2e45a5a7776b79732cd500c7462574f8fbe7ca23 (patch) | |
tree | 53ce2827050229194e5ba66d1397dd510612554c /distfoldd/watcher.cc | |
parent | c0183326a6447f931d4ec971963633a687e12c5e (diff) | |
download | distfold-master.tar.gz distfold-master.zip |
Diffstat (limited to 'distfoldd/watcher.cc')
-rw-r--r-- | distfoldd/watcher.cc | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/distfoldd/watcher.cc b/distfoldd/watcher.cc index 664ea58..39b68f3 100644 --- a/distfoldd/watcher.cc +++ b/distfoldd/watcher.cc @@ -19,10 +19,8 @@ Watcher::Watcher(const QString& path, QObject *parent) : _notifier = new QSocketNotifier(_fd, QSocketNotifier::Read, this); connect(_notifier, SIGNAL(activated(int)), SLOT(readInotify())); - QStringList l = scanDirs(QDir(path)); - foreach (const QString& s, l) { - addWatch(s); - } + // Scan directories and add watches + addWatches(scanDirs(QDir(path))); } void Watcher::readInotify() @@ -58,8 +56,9 @@ void Watcher::readInotify() if (event->mask & (IN_CREATE|IN_MOVED_TO)) { if (event->mask & IN_ISDIR) { - // TODO There might already be folders in here. - addWatch(filePath); + // Perform a recursive scan in case there are directories + // there already. + addWatches(scanDirs(QDir(filePath))); } emit pathAdded(filePath); } @@ -81,7 +80,7 @@ void Watcher::readInotify() QStringList Watcher::scanDirs(const QDir &dir) { Q_ASSERT(dir.isReadable()); - QStringList l(dir.absolutePath()); + QStringList l(dir.absolutePath()); // Add dir to the list QStringList sub_dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); foreach (const QString& s, sub_dirs) { @@ -92,6 +91,13 @@ QStringList Watcher::scanDirs(const QDir &dir) return l; } +void Watcher::addWatches(const QStringList &paths) +{ + foreach (const QString& s, paths) { + addWatch(s); + } +} + void Watcher::addWatch(const QString& path) { int wd = inotify_add_watch(_fd, path.toLocal8Bit().constData(), _mask); |