Notify user if there is a problem with the inotify watcher

This commit is contained in:
Daniel Molkentin 2013-08-07 14:59:41 +02:00
parent 9b319cf189
commit c24d6bd71c
7 changed files with 25 additions and 9 deletions

View file

@ -302,6 +302,11 @@ void Folder::slotThreadTreeWalkResult(const SyncFileItemVector& items)
_syncResult.setSyncFileItemVector(items);
}
void Folder::slotCatchWatcherError(const QString& error)
{
Logger::instance()->postGuiLog(tr("Error"), error);
}
void Folder::slotTerminateSync()
{
qDebug() << "folder " << alias() << " Terminating!";

View file

@ -177,6 +177,7 @@ private slots:
*/
void slotLocalPathChanged( const QString& );
void slotThreadTreeWalkResult(const SyncFileItemVector& );
void slotCatchWatcherError( const QString& );
protected:
bool init();

View file

@ -43,7 +43,7 @@ class FolderWatcherPrivate;
*/
class FolderWatcher : public QObject
{
Q_OBJECT
Q_OBJECT
public:
/**
* @param root Path of the root of the folder
@ -104,10 +104,10 @@ public slots:
void setEventsEnabledDelayed( int );
signals:
/**
* Emitted when one of the paths is changed
*/
/** Emitted when one of the paths is changed */
void folderChanged(const QStringList &pathList);
/** Emitted if an error occurs */
void error(const QString& error);
protected:
void setProcessTimer();

View file

@ -49,7 +49,12 @@ void FolderWatcherPrivate::slotAddFolderRecursive(const QString &path)
int subdirs = 0;
qDebug() << "(+) Watcher:" << path;
_inotify->addPath(path);
if (!_inotify->addPath(path)) {
FolderWatcher *fw = qobject_cast<FolderWatcher*>(parent());
emit fw->error(tr("Could not monitor directories due to system limitations.\n"
"The application will not work reliably. Please check the\n"
"documentation for possible fixes."));
}
QStringList watchedFolders(_inotify->directories());
// qDebug() << "currently watching " << watchedFolders;
QStringListIterator subfoldersIt(FileUtils::subFoldersList(path, FileUtils::SubFolderRecursive));

View file

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

View file

@ -115,14 +115,17 @@ INotify::~INotify()
delete _notifier;
}
void INotify::addPath(const QString &path)
bool INotify::addPath(const QString &path)
{
// Add an inotify watch.
int wd = inotify_add_watch(_fd, path.toUtf8().constData(), _mask);
if( wd > -1 )
if( wd > -1 ) {
_wds[path] = wd;
else
return true;
} else {
qDebug() << "WRN: Could not watch " << path << ':' << strerror(errno);
return false;
}
}
void INotify::removePath(const QString &path)

View file

@ -38,7 +38,7 @@ public:
INotify(QObject *parent, int mask);
~INotify();
void addPath(const QString &name);
bool addPath(const QString &name);
void removePath(const QString &name);
QStringList directories() const;