diff options
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_win.cpp | 65 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths.cpp | 42 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_json.cpp | 6 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_unix.cpp | 77 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_win.cpp | 6 |
5 files changed, 133 insertions, 63 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index 715e16bc7e..9b5b188475 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -56,6 +56,13 @@ QT_BEGIN_NAMESPACE +// #define WINQFSW_DEBUG +#ifdef WINQFSW_DEBUG +# define DEBUG qDebug +#else +# define DEBUG if (false) qDebug +#endif + QWindowsFileSystemWatcherEngine::Handle::Handle() : handle(INVALID_HANDLE_VALUE), flags(0u) { @@ -74,7 +81,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, QStringList *files, QStringList *directories) { - // qDebug()<<"Adding"<<paths.count()<<"to existing"<<(files->count() + directories->count())<<"watchers"; + DEBUG() << "Adding" << paths.count() << "to existing" << (files->count() + directories->count()) << "watchers"; QStringList p = paths; QMutableListIterator<QString> it(p); while (it.hasNext()) { @@ -101,7 +108,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, continue; } - // qDebug()<<"Looking for a thread/handle for"<<normalPath; + DEBUG() << "Looking for a thread/handle for" << normalPath; const QString absolutePath = isDir ? fileInfo.absoluteFilePath() : fileInfo.absolutePath(); const uint flags = isDir @@ -132,7 +139,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, handle = thread->handleForDir.value(absolutePath); if (handle.handle != INVALID_HANDLE_VALUE && handle.flags == flags) { // found a thread now insert... - // qDebug()<<" Found a thread"<<thread; + DEBUG() << "Found a thread" << thread; QHash<QString, QWindowsFileSystemWatcherEngine::PathInfo> &h = thread->pathInfoForHandle[handle.handle]; @@ -151,7 +158,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, // no thread found, first create a handle if (handle.handle == INVALID_HANDLE_VALUE || handle.flags != flags) { - // qDebug()<<" No thread found"; + DEBUG() << "No thread found"; // Volume and folder paths need a trailing slash for proper notification // (e.g. "c:" -> "c:/"). const QString effectiveAbsolutePath = @@ -167,8 +174,8 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, foreach(QWindowsFileSystemWatcherEngineThread *thread, threads) { QMutexLocker(&(thread->mutex)); if (thread->handles.count() < MAXIMUM_WAIT_OBJECTS) { - // qDebug() << " Added handle" << handle.handle << "for" << absolutePath << "to watch" << fileInfo.absoluteFilePath(); - // qDebug()<< " to existing thread"<<thread; + DEBUG() << "Added handle" << handle.handle << "for" << absolutePath << "to watch" << fileInfo.absoluteFilePath() + << "to existing thread " << thread; thread->handles.append(handle.handle); thread->handleForDir.insert(absolutePath, handle); @@ -186,7 +193,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, } if (!found) { QWindowsFileSystemWatcherEngineThread *thread = new QWindowsFileSystemWatcherEngineThread(); - //qDebug()<<" ###Creating new thread"<<thread<<"("<<(threads.count()+1)<<"threads)"; + DEBUG() << " ###Creating new thread" << thread << "(" << (threads.count()+1) << "threads)"; thread->handles.append(handle.handle); thread->handleForDir.insert(absolutePath, handle); @@ -215,7 +222,7 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path QStringList *files, QStringList *directories) { - // qDebug()<<"removePaths"<<paths; + DEBUG() << "removePaths" << paths; QStringList p = paths; QMutableListIterator<QString> it(p); while (it.hasNext()) { @@ -224,7 +231,7 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path if (normalPath.endsWith(QLatin1Char('/')) || normalPath.endsWith(QLatin1Char('\\'))) normalPath.chop(1); QFileInfo fileInfo(normalPath.toLower()); - // qDebug()<<"removing"<<normalPath; + DEBUG() << "removing" << normalPath; QString absolutePath = fileInfo.absoluteFilePath(); QList<QWindowsFileSystemWatcherEngineThread *>::iterator jt, end; end = threads.end(); @@ -250,7 +257,7 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path directories->removeAll(path); if (h.isEmpty()) { - // qDebug() << "Closing handle" << handle.handle; + DEBUG() << "Closing handle" << handle.handle; FindCloseChangeNotification(handle.handle); // This one might generate a notification int indexOfHandle = thread->handles.indexOf(handle.handle); @@ -263,7 +270,7 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path it.remove(); if (thread->handleForDir.isEmpty()) { - // qDebug()<<"Stopping thread "<<thread; + DEBUG() << "Stopping thread " << thread; locker.unlock(); thread->stop(); thread->wait(); @@ -336,7 +343,7 @@ void QWindowsFileSystemWatcherEngineThread::run() forever { QVector<HANDLE> handlesCopy = handles; locker.unlock(); - // qDebug() << "QWindowsFileSystemWatcherThread"<<this<<"waiting on" << handlesCopy.count() << "handles"; + DEBUG() << "QWindowsFileSystemWatcherThread" << this << "waiting on" << handlesCopy.count() << "handles"; DWORD r = WaitForMultipleObjects(handlesCopy.count(), handlesCopy.constData(), false, INFINITE); locker.relock(); do { @@ -344,12 +351,11 @@ void QWindowsFileSystemWatcherEngineThread::run() int m = msg; msg = 0; if (m == 'q') { - // qDebug() << "thread"<<this<<"told to quit"; + DEBUG() << "thread" << this << "told to quit"; return; } - if (m != '@') { - qDebug("QWindowsFileSystemWatcherEngine: unknown message '%c' send to thread", char(m)); - } + if (m != '@') + DEBUG() << "QWindowsFileSystemWatcherEngine: unknown message sent to thread: " << char(m); break; } else if (r > WAIT_OBJECT_0 && r < WAIT_OBJECT_0 + uint(handlesCopy.count())) { int at = r - WAIT_OBJECT_0; @@ -359,10 +365,20 @@ void QWindowsFileSystemWatcherEngineThread::run() // When removing a path, FindCloseChangeNotification might actually fire a notification // for some reason, so we must check if the handle exist in the handles vector if (handles.contains(handle)) { - // qDebug()<<"thread"<<this<<"Acknowledged handle:"<<at<<handle; + DEBUG() << "thread" << this << "Acknowledged handle:" << at << handle; QHash<QString, QWindowsFileSystemWatcherEngine::PathInfo> &h = pathInfoForHandle[handle]; + bool fakeRemove = false; + if (!FindNextChangeNotification(handle)) { const DWORD error = GetLastError(); + + if (error == ERROR_ACCESS_DENIED) { + // for directories, our object's handle appears to be woken up when the target of a + // watch is deleted, before the watched thing is actually deleted... + // anyway.. we're given an error code of ERROR_ACCESS_DENIED in that case. + fakeRemove = true; + } + qErrnoWarning(error, "%s", qPrintable(msgFindNextFailed(h))); } QMutableHashIterator<QString, QWindowsFileSystemWatcherEngine::PathInfo> it(h); @@ -370,9 +386,12 @@ void QWindowsFileSystemWatcherEngineThread::run() QHash<QString, QWindowsFileSystemWatcherEngine::PathInfo>::iterator x = it.next(); QString absolutePath = x.value().absolutePath; QFileInfo fileInfo(x.value().path); - // qDebug() << "checking" << x.key(); - if (!fileInfo.exists()) { - // qDebug() << x.key() << "removed!"; + DEBUG() << "checking" << x.key(); + + // i'm not completely sure the fileInfo.exist() check will ever work... see QTBUG-2331 + // ..however, I'm not completely sure enough to remove it. + if (fakeRemove || !fileInfo.exists()) { + DEBUG() << x.key() << "removed!"; if (x.value().isDir) emit directoryChanged(x.value().path, true); else @@ -381,7 +400,7 @@ void QWindowsFileSystemWatcherEngineThread::run() // close the notification handle if the directory has been removed if (h.isEmpty()) { - // qDebug() << "Thread closing handle" << handle; + DEBUG() << "Thread closing handle" << handle; FindCloseChangeNotification(handle); // This one might generate a notification int indexOfHandle = handles.indexOf(handle); @@ -392,11 +411,11 @@ void QWindowsFileSystemWatcherEngineThread::run() // h is now invalid } } else if (x.value().isDir) { - // qDebug() << x.key() << "directory changed!"; + DEBUG() << x.key() << "directory changed!"; emit directoryChanged(x.value().path, false); x.value() = fileInfo; } else if (x.value() != fileInfo) { - // qDebug() << x.key() << "file changed!"; + DEBUG() << x.key() << "file changed!"; emit fileChanged(x.value().path, false); x.value() = fileInfo; } diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index 78bf6c7b96..55f824cdeb 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -267,6 +267,48 @@ QString QStandardPaths::findExecutable(const QString &executableName, const QStr an empty QString if no relevant location can be found. */ +#ifndef Q_OS_MAC +QString QStandardPaths::displayName(StandardLocation type) +{ + switch (type) { + case DesktopLocation: + return QCoreApplication::translate("QStandardPaths", "Desktop"); + case DocumentsLocation: + return QCoreApplication::translate("QStandardPaths", "Documents"); + case FontsLocation: + return QCoreApplication::translate("QStandardPaths", "Fonts"); + case ApplicationsLocation: + return QCoreApplication::translate("QStandardPaths", "Applications"); + case MusicLocation: + return QCoreApplication::translate("QStandardPaths", "Music"); + case MoviesLocation: + return QCoreApplication::translate("QStandardPaths", "Movies"); + case PicturesLocation: + return QCoreApplication::translate("QStandardPaths", "Pictures"); + case TempLocation: + return QCoreApplication::translate("QStandardPaths", "Temporary Directory"); + case HomeLocation: + return QCoreApplication::translate("QStandardPaths", "Home"); + case DataLocation: + return QCoreApplication::translate("QStandardPaths", "Application Data"); + case CacheLocation: + return QCoreApplication::translate("QStandardPaths", "Cache"); + case GenericDataLocation: + return QCoreApplication::translate("QStandardPaths", "Shared Data"); + case RuntimeLocation: + return QCoreApplication::translate("QStandardPaths", "Runtime"); + case ConfigLocation: + return QCoreApplication::translate("QStandardPaths", "Configuration"); + case GenericCacheLocation: + return QCoreApplication::translate("QStandardPaths", "Shared Cache"); + case DownloadLocation: + return QCoreApplication::translate("QStandardPaths", "Download"); + } + // not reached + return QString(); +} +#endif + QT_END_NAMESPACE #endif // QT_NO_STANDARDPATHS diff --git a/src/corelib/io/qstandardpaths_json.cpp b/src/corelib/io/qstandardpaths_json.cpp index 52b194bea8..7d7a0a9f28 100644 --- a/src/corelib/io/qstandardpaths_json.cpp +++ b/src/corelib/io/qstandardpaths_json.cpp @@ -173,12 +173,6 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) return dirs; } -QString QStandardPaths::displayName(StandardLocation type) -{ - Q_UNUSED(type); - return QString(); -} - QT_END_NAMESPACE #endif // QT_NO_STANDARDPATHS diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index 5499751751..1a2ae96edb 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -53,6 +53,16 @@ QT_BEGIN_NAMESPACE +static void appendOrganizationAndApp(QString &path) +{ + const QString org = QCoreApplication::organizationName(); + if (!org.isEmpty()) + path += QLatin1Char('/') + org; + const QString appName = QCoreApplication::applicationName(); + if (!appName.isEmpty()) + path += QLatin1Char('/') + appName; +} + QString QStandardPaths::writableLocation(StandardLocation type) { switch (type) { @@ -67,12 +77,8 @@ QString QStandardPaths::writableLocation(StandardLocation type) QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME")); if (xdgCacheHome.isEmpty()) xdgCacheHome = QDir::homePath() + QLatin1String("/.cache"); - if (type == QStandardPaths::CacheLocation) { - if (!QCoreApplication::organizationName().isEmpty()) - xdgCacheHome += QLatin1Char('/') + QCoreApplication::organizationName(); - if (!QCoreApplication::applicationName().isEmpty()) - xdgCacheHome += QLatin1Char('/') + QCoreApplication::applicationName(); - } + if (type == QStandardPaths::CacheLocation) + appendOrganizationAndApp(xdgCacheHome); return xdgCacheHome; } case DataLocation: @@ -81,12 +87,8 @@ QString QStandardPaths::writableLocation(StandardLocation type) QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME")); if (xdgDataHome.isEmpty()) xdgDataHome = QDir::homePath() + QLatin1String("/.local/share"); - if (type == QStandardPaths::DataLocation) { - if (!QCoreApplication::organizationName().isEmpty()) - xdgDataHome += QLatin1Char('/') + QCoreApplication::organizationName(); - if (!QCoreApplication::applicationName().isEmpty()) - xdgDataHome += QLatin1Char('/') + QCoreApplication::applicationName(); - } + if (type == QStandardPaths::DataLocation) + appendOrganizationAndApp(xdgDataHome); return xdgDataHome; } case ConfigLocation: @@ -229,36 +231,55 @@ QString QStandardPaths::writableLocation(StandardLocation type) return path; } +static QStringList xdgDataDirs() +{ + QStringList dirs; + // http://standards.freedesktop.org/basedir-spec/latest/ + QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS")); + if (xdgDataDirsEnv.isEmpty()) { + dirs.append(QString::fromLatin1("/usr/local/share")); + dirs.append(QString::fromLatin1("/usr/share")); + } else { + dirs = xdgDataDirsEnv.split(QLatin1Char(':')); + } + return dirs; +} + QStringList QStandardPaths::standardLocations(StandardLocation type) { QStringList dirs; - if (type == ConfigLocation) { + switch (type) { + case ConfigLocation: + { // http://standards.freedesktop.org/basedir-spec/latest/ - QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS")); + const QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS")); if (xdgConfigDirs.isEmpty()) dirs.append(QString::fromLatin1("/etc/xdg")); else dirs = xdgConfigDirs.split(QLatin1Char(':')); - } else if (type == GenericDataLocation) { - // http://standards.freedesktop.org/basedir-spec/latest/ - QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_DATA_DIRS")); - if (xdgConfigDirs.isEmpty()) { - dirs.append(QString::fromLatin1("/usr/local/share")); - dirs.append(QString::fromLatin1("/usr/share")); - } else - dirs = xdgConfigDirs.split(QLatin1Char(':')); + } + break; + case GenericDataLocation: + dirs = xdgDataDirs(); + break; + case ApplicationsLocation: + dirs = xdgDataDirs(); + for (int i = 0; i < dirs.count(); ++i) + dirs[i].append(QLatin1String("/applications")); + break; + case DataLocation: + dirs = xdgDataDirs(); + for (int i = 0; i < dirs.count(); ++i) + appendOrganizationAndApp(dirs[i]); + break; + default: + break; } const QString localDir = writableLocation(type); dirs.prepend(localDir); return dirs; } -QString QStandardPaths::displayName(StandardLocation type) -{ - Q_UNUSED(type); - return QString(); -} - QT_END_NAMESPACE #endif // QT_NO_STANDARDPATHS diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp index 848dd448eb..8bd32eb1d4 100644 --- a/src/corelib/io/qstandardpaths_win.cpp +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -206,12 +206,6 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) return dirs; } -QString QStandardPaths::displayName(StandardLocation type) -{ - Q_UNUSED(type); - return QString(); -} - QT_END_NAMESPACE #endif // QT_NO_STANDARDPATHS |