diff --git a/CMakeLists.txt b/CMakeLists.txt index 71e6b5bdb9..7598b72318 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,16 +78,10 @@ endif() find_package(Neon REQUIRED) find_package(Csync REQUIRED) find_package(QtKeychain REQUIRED) -if(UNIX) -find_package(INotify REQUIRED) -else() -find_package(INotify) -endif() find_package(Sphinx) find_package(PdfLatex) set(WITH_QTKEYCHAIN ${QTKEYCHAIN_FOUND}) -set(USE_INOTIFY ${INOTIFY_FOUND}) configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) diff --git a/cmake/modules/FindINotify.cmake b/cmake/modules/FindINotify.cmake deleted file mode 100644 index dd5dd1b16f..0000000000 --- a/cmake/modules/FindINotify.cmake +++ /dev/null @@ -1,19 +0,0 @@ -# This module defines -# INOTIFY_INCLUDE_DIR, where to find inotify.h, etc. -# INOTIFY_FOUND, If false, do not try to use inotify. -# also defined, but not for general use are -# INOTIFY_LIBRARY, where to find the inotify library. - -find_path(INOTIFY_INCLUDE_DIR sys/inotify.h - HINTS /usr/include/${CMAKE_LIBRARY_ARCHITECTURE}) -mark_as_advanced(INOTIFY_INCLUDE_DIR) - -# all listed variables are TRUE -# handle the QUIETLY and REQUIRED arguments and set INOTIFY_FOUND to TRUE if -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(INOTIFY DEFAULT_MSG INOTIFY_INCLUDE_DIR) - -IF(INOTIFY_FOUND) - SET(INotify_INCLUDE_DIRS ${INOTIFY_INCLUDE_DIR}) -ENDIF(INOTIFY_FOUND) - diff --git a/config.h.in b/config.h.in index 057fe28c6a..1dc2019b5f 100644 --- a/config.h.in +++ b/config.h.in @@ -1,7 +1,6 @@ #ifndef CONFIG_H #define CONFIG_H -#cmakedefine USE_INOTIFY 1 #cmakedefine WITH_QTKEYCHAIN 1 #cmakedefine GIT_SHA1 "@GIT_SHA1@" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 305cb2de71..e17b35bd50 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -112,10 +112,8 @@ set(libsync_HEADERS 3rdparty/qjson/json.h ) -IF( INOTIFY_FOUND ) - set(libsync_SRCS ${libsync_SRCS} mirall/inotify.cpp) +IF( NOT WIN32 AND NOT APPLE ) set(libsync_SRCS ${libsync_SRCS} mirall/folderwatcher_qt.cpp) - set(libsync_HEADERS ${libsync_HEADERS} mirall/inotify.h) set(libsync_HEADERS ${libsync_HEADERS} mirall/folderwatcher_qt.h) ENDIF() IF( WIN32 ) @@ -173,12 +171,6 @@ list(APPEND libsync_LINK_TARGETS ${HTTPBF_LIBRARY} ) -IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") - list(APPEND libsync_LINK_TARGETS - inotify - ) -ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") - if(QTKEYCHAIN_FOUND) list(APPEND libsync_LINK_TARGETS ${QTKEYCHAIN_LIBRARY}) include_directories(${QTKEYCHAIN_INCLUDE_DIR}) @@ -295,12 +287,6 @@ set(mirall_HEADERS mirall/socketapi.h ) -if( UNIX AND NOT APPLE) - if(NOT DEFINED USE_INOTIFY) - set(USE_INOTIFY ON) - endif() -endif() - # csync is required. include_directories(${CSYNC_INCLUDE_DIR}/csync ${CSYNC_INCLUDE_DIR} ${CSYNC_INCLUDE_DIR}/httpbf/src ${CSYNC_BUILD_PATH}/src) include_directories(${3rdparty_INC}) diff --git a/src/mirall/folderman.cpp b/src/mirall/folderman.cpp index 3570e95d49..dbb9a6f6b8 100644 --- a/src/mirall/folderman.cpp +++ b/src/mirall/folderman.cpp @@ -16,7 +16,6 @@ #include "mirall/mirallconfigfile.h" #include "mirall/folder.h" #include "mirall/syncresult.h" -#include "mirall/inotify.h" #include "mirall/theme.h" #include diff --git a/src/mirall/folderwatcher.cpp b/src/mirall/folderwatcher.cpp index e85e26a288..8fdbb8696e 100644 --- a/src/mirall/folderwatcher.cpp +++ b/src/mirall/folderwatcher.cpp @@ -14,7 +14,6 @@ // event masks #include "mirall/folderwatcher.h" #include "mirall/folder.h" -#include "mirall/inotify.h" #include diff --git a/src/mirall/folderwatcher.h b/src/mirall/folderwatcher.h index a7520c58fa..a1cfd32f4e 100644 --- a/src/mirall/folderwatcher.h +++ b/src/mirall/folderwatcher.h @@ -22,7 +22,7 @@ #include "mirall/folderwatcher_win.h" #elif defined(Q_OS_MAC) #include "mirall/folderwatcher_mac.h" -#elif defined(USE_INOTIFY) +#elif defined(Q_OS_LINUX) #include "mirall/folderwatcher_qt.h" #endif diff --git a/src/mirall/folderwatcher_qt.h b/src/mirall/folderwatcher_qt.h index aa095aa9ae..5ae6ba3358 100644 --- a/src/mirall/folderwatcher_qt.h +++ b/src/mirall/folderwatcher_qt.h @@ -20,7 +20,6 @@ namespace Mirall { -class INotify; class FolderWatcher; class FolderWatcherPrivate : public QObject { diff --git a/src/mirall/inotify.cpp b/src/mirall/inotify.cpp deleted file mode 100644 index 7032feab18..0000000000 --- a/src/mirall/inotify.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * - * Originally based on example copyright (c) Ashish Shukla - * Ported to use QSocketNotifier later instead of a thread loop - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ -#include "config.h" - -#include - -#include "inotify.h" -#include "mirall/folder.h" - -#include -#include -#include -#include -#include - -#include "inotify.h" - -// Buffer Size for read() buffer -#define DEFAULT_READ_BUFFERSIZE 2048 - -namespace Mirall { - -INotify::INotify(QObject *parent, int mask) - : QObject(parent), - _mask(mask) -{ - _fd = inotify_init(); - if (_fd == -1) - qDebug() << Q_FUNC_INFO << "notify_init() failed: " << strerror(errno); - _notifier = new QSocketNotifier(_fd, QSocketNotifier::Read); - connect(_notifier, SIGNAL(activated(int)), SLOT(slotActivated(int))); - _buffer_size = DEFAULT_READ_BUFFERSIZE; - _buffer = (char *) malloc(_buffer_size); -} - -void INotify::slotActivated(int /*fd*/) -{ - int len; - struct inotify_event* event; - int i; - int error; - - do { - len = read(_fd, _buffer, _buffer_size); - error = errno; - /** - * From inotify documentation: - * - * The behavior when the buffer given to read(2) is too - * small to return information about the next event - * depends on the kernel version: in kernels before 2.6.21, - * read(2) returns 0; since kernel 2.6.21, read(2) fails with - * the error EINVAL. - */ - if (len < 0 && error == EINVAL) - { - // double the buffer size - qWarning() << "buffer size too small"; - _buffer_size *= 2; - _buffer = (char *) realloc(_buffer, _buffer_size); - /* and try again ... */ - continue; - } - } while (false); - - /* TODO handle len == 0 */ - - // reset counter - i = 0; - // while there are enough events in the buffer - while(i + sizeof(struct inotify_event) < static_cast(len)) { - // cast an inotify_event - event = (struct inotify_event*)&_buffer[i]; - // with the help of watch descriptor, retrieve, corresponding INotify - if (event == NULL) { - qDebug() << "NULL event"; - i += sizeof(struct inotify_event); - continue; - } - - // fire event - if (event->len > 0) { - QStringList paths(_wds.keys(event->wd)); - foreach (QString path, paths) - emit notifyEvent(event->mask, event->cookie, path + "/" + QString::fromUtf8(event->name)); - } - - // increment counter - i += sizeof(struct inotify_event) + event->len; - } -} - -INotify::~INotify() -{ - // Remove all inotify watchs. - QString key; - foreach (key, _wds.keys()) - inotify_rm_watch(_fd, _wds.value(key)); - - close(_fd); - free(_buffer); - delete _notifier; -} - -bool INotify::addPath(const QString &path) -{ - // Add an inotify watch. - int wd = inotify_add_watch(_fd, path.toUtf8().constData(), _mask); - if( wd > -1 ) { - _wds[path] = wd; - return true; - } else { - qDebug() << "WRN: Could not watch " << path << ':' << strerror(errno); - return false; - } -} - -void INotify::removePath(const QString &path) -{ - // Remove the inotify watch. - inotify_rm_watch(_fd, _wds[path]); - _wds.remove(path); -} - -QStringList INotify::directories() const -{ - return _wds.keys(); -} - -} // ns mirall - diff --git a/src/mirall/inotify.h b/src/mirall/inotify.h deleted file mode 100644 index 8a08bd018b..0000000000 --- a/src/mirall/inotify.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) by Duncan Mac-Vicar P. - * - * Originally based on example copyright (c) Ashish Shukla - * - * Ported to use QSocketNotifier later instead of a thread loop - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -#ifndef MIRALL_INOTIFY_H -#define MIRALL_INOTIFY_H - -#include -#include -#include -#include - -class QSocketNotifier; - -namespace Mirall -{ - -class INotify : public QObject -{ - Q_OBJECT - -public: - - INotify(QObject *parent, int mask); - ~INotify(); - - bool addPath(const QString &name); - void removePath(const QString &name); - - QStringList directories() const; - -protected slots: - void slotActivated(int); - -signals: - void notifyEvent(int mask, int cookie, const QString &name); - -private: - int _fd; - QSocketNotifier *_notifier; - // the mask is shared for all paths - int _mask; - QMap _wds; - - size_t _buffer_size; - char *_buffer; -}; - -} - -#endif