Add the new directories comming from the sync in the watcher

This commit is contained in:
Olivier Goffart 2013-08-19 17:41:42 +02:00
parent a19a960b5e
commit b4c116e2a2
7 changed files with 50 additions and 3 deletions

View file

@ -297,11 +297,21 @@ void Folder::bubbleUpSyncResult()
newItems++; newItems++;
if (firstItemNew.isEmpty()) if (firstItemNew.isEmpty())
firstItemNew = item; firstItemNew = item;
if (item._type == SyncFileItem::Directory) {
_watcher->addPath(path() + item._file);
}
break; break;
case CSYNC_INSTRUCTION_REMOVE: case CSYNC_INSTRUCTION_REMOVE:
removedItems++; removedItems++;
if (firstItemDeleted.isEmpty()) if (firstItemDeleted.isEmpty())
firstItemDeleted = item; firstItemDeleted = item;
if (item._type == SyncFileItem::Directory) {
_watcher->removePath(path() + item._file);
}
break; break;
case CSYNC_INSTRUCTION_UPDATED: case CSYNC_INSTRUCTION_UPDATED:
updatedItems++; updatedItems++;

View file

@ -172,5 +172,16 @@ void FolderWatcher::changeDetected(const QString& f)
setProcessTimer(); setProcessTimer();
} }
void FolderWatcher::addPath(const QString &path )
{
_d->addPath(path);
}
void FolderWatcher::removePath(const QString &path )
{
_d->removePath(path);
}
} // namespace Mirall } // namespace Mirall

View file

@ -88,6 +88,15 @@ public:
void setEventInterval(int seconds); void setEventInterval(int seconds);
QStringList ignores() const; QStringList ignores() const;
/**
* Not all backends are recursive by default.
* Those need to be notified when a directory is added or removed while the watcher is disabled.
* This is a no-op for backend that are recursive
*/
void addPath(const QString&);
void removePath(const QString&);
public slots: public slots:
/** /**
* Enabled or disables folderChanged() events. * Enabled or disables folderChanged() events.

View file

@ -119,9 +119,8 @@ void FolderWatcherPrivate::slotINotifyEvent(int mask, int /*cookie*/, const QStr
} }
else if (mask & IN_DELETE) { else if (mask & IN_DELETE) {
//qDebug() << cookie << " DELETE: " << path; //qDebug() << cookie << " DELETE: " << path;
if ( QFileInfo(path).isDir() && _inotify->directories().contains(path) ) { if ( QFileInfo(path).isDir() ) {
qDebug() << "(-) Watcher:" << path; removePath(path);
_inotify->removePath(path);
} }
} }
else if (mask & IN_CLOSE_WRITE) { else if (mask & IN_CLOSE_WRITE) {
@ -160,4 +159,13 @@ void FolderWatcherPrivate::slotINotifyEvent(int mask, int /*cookie*/, const QStr
_parent->setProcessTimer(); _parent->setProcessTimer();
} }
void FolderWatcherPrivate::removePath(const QString &path )
{
if (_inotify->directories().contains(path) ) {
qDebug() << "(-) Watcher:" << path;
_inotify->removePath(path);
}
}
} // namespace Mirall } // namespace Mirall

View file

@ -26,6 +26,8 @@ class FolderWatcherPrivate : public QObject {
Q_OBJECT Q_OBJECT
public: public:
FolderWatcherPrivate(FolderWatcher *p); FolderWatcherPrivate(FolderWatcher *p);
void addPath(const QString &path) { slotAddFolderRecursive(path); }
void removePath(const QString &);
signals: signals:
void error(const QString& error); void error(const QString& error);
private slots: private slots:

View file

@ -31,6 +31,9 @@ public:
FolderWatcherPrivate(FolderWatcher *p); FolderWatcherPrivate(FolderWatcher *p);
~FolderWatcherPrivate(); ~FolderWatcherPrivate();
void addPath(const QString &) {}
void removePath(const QString &) {}
void startWatching(); void startWatching();
void doNotifyParent(); void doNotifyParent();

View file

@ -48,6 +48,10 @@ class FolderWatcherPrivate : public QObject {
public: public:
FolderWatcherPrivate(FolderWatcher *p); FolderWatcherPrivate(FolderWatcher *p);
~FolderWatcherPrivate(); ~FolderWatcherPrivate();
void addPath(const QString &) {}
void removePath(const QString &) {}
private: private:
FolderWatcher *_parent; FolderWatcher *_parent;
WatcherThread *_thread; WatcherThread *_thread;