42 #include "qplatformdefs.h" 46 #ifndef QT_NO_FILESYSTEMWATCHER 56 #include <sys/types.h> 63 #include "private/qcore_unix_p.h" 69 #define DN_ACCESS 0x00000001 70 #define DN_MODIFY 0x00000002 71 #define DN_CREATE 0x00000004 72 #define DN_DELETE 0x00000008 73 #define DN_RENAME 0x00000010 74 #define DN_ATTRIB 0x00000020 75 #define DN_MULTISHOT 0x80000000 131 memset(&action, 0,
sizeof(action));
133 action.sa_flags = SA_SIGINFO;
135 if (!(oldAction.sa_flags & SA_SIGINFO))
209 iter != fdToDirectory.constEnd();
224 qFatal(
"QDnotifyFileSystemWatcherEngine thread should not be run");
232 QMutableListIterator<QString>
it(p);
234 while (it.hasNext()) {
243 bool isDir = fi.
isDir();
245 if (isDir && directories->
contains(path)) {
247 }
else if(!isDir && files->
contains(path)) {
255 int fd = pathToFD[path];
263 QDir parentDir(path);
274 int parentFd = parent ?
qt_safe_dup(::dirfd(parent)) : 0;
277 if(parent) QT_CLOSEDIR(parent);
280 if(::
fcntl(fd, F_SETSIG, SIGIO) ||
281 ::
fcntl(fd, F_NOTIFY, DN_MODIFY | DN_CREATE | DN_DELETE |
282 DN_RENAME | DN_ATTRIB | DN_MULTISHOT) ||
283 (parent && ::
fcntl(parentFd, F_SETSIG, SIGIO)) ||
284 (parent && ::
fcntl(parentFd, F_NOTIFY, DN_DELETE | DN_RENAME |
294 fdToDirectory.insert(fd, dir);
295 pathToFD.insert(path, fd);
297 parentToFD.insert(parentFd, fd);
300 Directory &directory = fdToDirectory[fd];
308 directory.
files.append(file);
315 directories->
append(path);
321 dnotifySignal()->startNotify();
331 QMutableListIterator<QString>
it(p);
332 while (it.hasNext()) {
335 int fd = pathToFD.take(path);
340 Directory &directory = fdToDirectory[fd];
342 if(directory.
path == path) {
346 for(
int ii = 0; ii < directory.
files.count(); ++ii) {
347 if(directory.
files.at(ii).path == path) {
348 directory.
files.removeAt(ii);
357 pathToFD.remove(directory.
path);
358 fdToDirectory.remove(fd);
377 bool wasParent =
false;
379 if(iter == fdToDirectory.end()) {
381 if(pIter == parentToFD.
end())
384 iter = fdToDirectory.find(*pIter);
385 if (iter == fdToDirectory.end())
393 for(
int ii = 0; ii < directory.
files.count(); ++ii) {
401 directory.
files.removeAt(ii);
405 emit fileChanged(filePath, removed);
418 emit directoryChanged(path, removed);
425 parentToFD.remove(directory.
parentFd);
427 fdToDirectory.erase(iter);
441 QFile::Permissions nPermissions = fi.
permissions();
443 if(nLastWrite != lastWrite ||
444 nOwnerId != ownerId ||
445 nGroupId != groupId ||
446 nPermissions != permissions) {
449 permissions = nPermissions;
450 lastWrite = nLastWrite;
459 #include "qfilesystemwatcher_dnotify.moc" 461 #endif // QT_NO_FILESYSTEMWATCHER The QDir class provides access to directory structures and their contents.
static void(* qfswd_old_sigio_handler)(int)=0
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
virtual ~QDnotifySignalThread()
#define QT_END_NAMESPACE
This macro expands to.
void lock()
Locks the mutex.
The QMutex class provides access serialization between threads.
#define it(className, varName)
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
virtual void run()
The starting point for the thread.
static void(* qfswd_old_sigio_action)(int, siginfo_t *, void *)=0
bool exists() const
Returns true if the file exists; otherwise returns false.
static int qt_safe_close(int fd)
The QString class provides a Unicode character string.
The QHash class is a template class that provides a hash-table-based dictionary.
QFile::Permissions permissions() const
Returns the complete OR-ed together combination of QFile::Permissions for the file.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
void quit()
Tells the thread's event loop to exit with return code 0 (success).
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
bool cdUp()
Changes directory by moving one directory up from the QDir's current directory.
uint ownerId() const
Returns the id of the owner of the file.
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
The QStringList class provides a list of strings.
static int qt_safe_pipe(int pipefd[2], int flags=0)
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
void unlock()
Unlocks the mutex.
QString canonicalPath() const
Returns the file's path canonical path (excluding the file name), i.e.
bool wait(QMutex *mutex, unsigned long time=ULONG_MAX)
const char * constData() const
Returns a pointer to the data stored in the byte array.
static QDnotifyFileSystemWatcherEngine * create()
Q_CORE_EXPORT void qFatal(const char *,...)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
The QDateTime class provides date and time functions.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
static QCoreApplication * instance()
Returns a pointer to the application's QCoreApplication (or QApplication) instance.
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().
int sigaction(int, const struct sigaction *, struct sigaction *)
QObject * parent() const
Returns a pointer to the parent object.
bool wait(unsigned long time=ULONG_MAX)
Blocks the thread until either of these conditions is met:
int exec()
Enters the event loop and waits until exit() is called, returning the value that was passed to exit()...
QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories)
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories)
virtual ~QDnotifyFileSystemWatcherEngine()
uint groupId() const
Returns the id of the group the file belongs to.
static void qfswd_sigio_monitor(int signum, siginfo_t *i, void *v)
QString path() const
Returns the path.
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
The QFileInfo class provides system-independent file information.
QString filePath() const
Returns the file name, including the path (which may be absolute or relative).
bool isRoot() const
Returns true if the directory is the root directory; otherwise returns false.
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
QDnotifyFileSystemWatcherEngine()
The QThread class provides a platform-independent way to manage threads.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
bool isRunning() const
Returns true if the thread is running; otherwise returns false.
void run()
The starting point for the thread.
static int qfswd_fileChanged_pipe[2]
static qint64 qt_safe_write(int fd, const void *data, qint64 len)
static qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
static int qt_safe_dup(int oldfd, int atleast=0, int flags=FD_CLOEXEC)
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
QDateTime lastModified() const
Returns the date and time when the file was last modified.