summaryrefslogtreecommitdiff
path: root/distfoldd
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2013-07-27 16:40:52 +0200
committerJavier S. Pedro <maemo@javispedro.com>2013-07-27 16:40:52 +0200
commit2e45a5a7776b79732cd500c7462574f8fbe7ca23 (patch)
tree53ce2827050229194e5ba66d1397dd510612554c /distfoldd
parentc0183326a6447f931d4ec971963633a687e12c5e (diff)
downloaddistfold-2e45a5a7776b79732cd500c7462574f8fbe7ca23.tar.gz
distfold-2e45a5a7776b79732cd500c7462574f8fbe7ca23.zip
fix inotify race conditionHEADmaster
Diffstat (limited to 'distfoldd')
-rw-r--r--distfoldd/watcher.cc20
-rw-r--r--distfoldd/watcher.h1
2 files changed, 14 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);
diff --git a/distfoldd/watcher.h b/distfoldd/watcher.h
index 861248e..74a9162 100644
--- a/distfoldd/watcher.h
+++ b/distfoldd/watcher.h
@@ -22,6 +22,7 @@ private slots:
private:
QStringList scanDirs(const QDir& dir);
+ void addWatches(const QStringList &paths);
void addWatch(const QString& path);
void removeWatch(const QString& path);
void removeWatch(int wd);