diff options
author | Iikka Eklund <iikka.eklund@digia.com> | 2014-04-02 07:36:48 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-02 07:36:48 +0200 |
commit | d6f58e5e17d58c640fc7779652008fda0d66f41d (patch) | |
tree | d50d27e260c9eaf4bc2bcb4480b8a069a3aed857 /src/corelib/io | |
parent | 83de197a57ff6c3e5bbad26bd871981285384fcb (diff) | |
parent | 0ab63b035a649dc1982c867cd37d466d249004b9 (diff) |
Merge "Merge remote-tracking branch 'origin/stable' into dev" into refs/staging/dev
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_fsevents.mm | 134 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_fsevents_p.h | 13 | ||||
-rw-r--r-- | src/corelib/io/qsettings.cpp | 6 | ||||
-rw-r--r-- | src/corelib/io/qsettings_mac.cpp | 40 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_win.cpp | 25 |
5 files changed, 156 insertions, 62 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_fsevents.mm b/src/corelib/io/qfilesystemwatcher_fsevents.mm index cb6ddd913e..bfcae2a3a2 100644 --- a/src/corelib/io/qfilesystemwatcher_fsevents.mm +++ b/src/corelib/io/qfilesystemwatcher_fsevents.mm @@ -55,7 +55,7 @@ #include <qfileinfo.h> #include <qvarlengtharray.h> -//#define FSEVENT_DEBUG +#undef FSEVENT_DEBUG #ifdef FSEVENT_DEBUG # define DEBUG if (true) qDebug #else @@ -76,14 +76,16 @@ static void callBackFunction(ConstFSEventStreamRef streamRef, engine->processEvent(streamRef, numEvents, paths, eventFlags, eventIds); } -void QFseventsFileSystemWatcherEngine::checkDir(DirsByName::iterator &it) +bool QFseventsFileSystemWatcherEngine::checkDir(DirsByName::iterator &it) { + bool needsRestart = false; + QT_STATBUF st; const QString &name = it.key(); Info &info = it->dirInfo; const int res = QT_STAT(QFile::encodeName(name), &st); if (res == -1) { - derefPath(info.watchedPath); + needsRestart |= derefPath(info.watchedPath); emit emitDirectoryChanged(info.origPath, true); it = watchedDirectories.erase(it); } else if (st.st_ctimespec != info.ctime || st.st_mode != info.mode) { @@ -127,26 +129,34 @@ void QFseventsFileSystemWatcherEngine::checkDir(DirsByName::iterator &it) if (dirChanged) emit emitDirectoryChanged(info.origPath, false); } + + return needsRestart; } -void QFseventsFileSystemWatcherEngine::rescanDirs(const QString &path) +bool QFseventsFileSystemWatcherEngine::rescanDirs(const QString &path) { + bool needsRestart = false; + for (DirsByName::iterator it = watchedDirectories.begin(); it != watchedDirectories.end(); ) { if (it.key().startsWith(path)) - checkDir(it); + needsRestart |= checkDir(it); else ++it; } + + return needsRestart; } -void QFseventsFileSystemWatcherEngine::rescanFiles(InfoByName &filesInPath) +bool QFseventsFileSystemWatcherEngine::rescanFiles(InfoByName &filesInPath) { + bool needsRestart = false; + for (InfoByName::iterator it = filesInPath.begin(); it != filesInPath.end(); ) { QT_STATBUF st; QString name = it.key(); const int res = QT_STAT(QFile::encodeName(name), &st); if (res == -1) { - derefPath(it->watchedPath); + needsRestart |= derefPath(it->watchedPath); emit emitFileChanged(it.value().origPath, true); it = filesInPath.erase(it); continue; @@ -158,13 +168,17 @@ void QFseventsFileSystemWatcherEngine::rescanFiles(InfoByName &filesInPath) ++it; } + + return needsRestart; } -void QFseventsFileSystemWatcherEngine::rescanFiles(const QString &path) +bool QFseventsFileSystemWatcherEngine::rescanFiles(const QString &path) { + bool needsRestart = false; + for (FilesByPath::iterator i = watchedFiles.begin(); i != watchedFiles.end(); ) { if (i.key().startsWith(path)) { - rescanFiles(i.value()); + needsRestart |= rescanFiles(i.value()); if (i.value().isEmpty()) { i = watchedFiles.erase(i); continue; @@ -173,6 +187,8 @@ void QFseventsFileSystemWatcherEngine::rescanFiles(const QString &path) ++i; } + + return needsRestart; } void QFseventsFileSystemWatcherEngine::processEvent(ConstFSEventStreamRef streamRef, @@ -184,11 +200,20 @@ void QFseventsFileSystemWatcherEngine::processEvent(ConstFSEventStreamRef stream #if defined(Q_OS_OSX) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_6 Q_UNUSED(streamRef); + bool needsRestart = false; + QMutexLocker locker(&lock); for (size_t i = 0; i < numEvents; ++i) { FSEventStreamEventFlags eFlags = eventFlags[i]; DEBUG("Change %llu in %s, flags %x", eventIds[i], eventPaths[i], (unsigned int)eFlags); + + if (eFlags & kFSEventStreamEventFlagEventIdsWrapped) { + DEBUG("\tthe event ids wrapped"); + lastReceivedEvent = 0; + } + lastReceivedEvent = qMax(lastReceivedEvent, eventIds[i]); + QString path = QFile::decodeName(eventPaths[i]); if (path.endsWith(QDir::separator())) path = path.mid(0, path.size() - 1); @@ -199,38 +224,36 @@ void QFseventsFileSystemWatcherEngine::processEvent(ConstFSEventStreamRef stream DEBUG("\t\t... user dropped."); if (eFlags & kFSEventStreamEventFlagKernelDropped) DEBUG("\t\t... kernel dropped."); - rescanDirs(path); - rescanFiles(path); + needsRestart |= rescanDirs(path); + needsRestart |= rescanFiles(path); continue; } - if (eFlags & kFSEventStreamEventFlagEventIdsWrapped) { - DEBUG("\tthe event ids wrapped"); - // TODO: verify if we need to do something - } - if (eFlags & kFSEventStreamEventFlagRootChanged) { // re-check everything: DirsByName::iterator dirIt = watchedDirectories.find(path); if (dirIt != watchedDirectories.end()) - checkDir(dirIt); - rescanFiles(path); + needsRestart |= checkDir(dirIt); + needsRestart |= rescanFiles(path); continue; } if ((eFlags & kFSEventStreamEventFlagItemIsDir) && (eFlags & kFSEventStreamEventFlagItemRemoved)) - rescanDirs(path); + needsRestart |= rescanDirs(path); // check watched directories: DirsByName::iterator dirIt = watchedDirectories.find(path); if (dirIt != watchedDirectories.end()) - checkDir(dirIt); + needsRestart |= checkDir(dirIt); // check watched files: FilesByPath::iterator pIt = watchedFiles.find(path); if (pIt != watchedFiles.end()) - rescanFiles(pIt.value()); + needsRestart |= rescanFiles(pIt.value()); } + + if (needsRestart) + emit scheduleStreamRestart(); #else // This is a work-around for moc: when we put the version check at the top of the header file, // moc will still see the Q_OBJECT macro and generate a meta-object when compiling for 10.6, @@ -248,14 +271,23 @@ void QFseventsFileSystemWatcherEngine::processEvent(ConstFSEventStreamRef stream void QFseventsFileSystemWatcherEngine::doEmitFileChanged(const QString path, bool removed) { + DEBUG() << "emitting fileChanged for" << path << "with removed =" << removed; emit fileChanged(path, removed); } void QFseventsFileSystemWatcherEngine::doEmitDirectoryChanged(const QString path, bool removed) { + DEBUG() << "emitting directoryChanged for" << path << "with removed =" << removed; emit directoryChanged(path, removed); } +void QFseventsFileSystemWatcherEngine::restartStream() +{ + QMutexLocker locker(&lock); + stopStream(); + startStream(); +} + QFseventsFileSystemWatcherEngine *QFseventsFileSystemWatcherEngine::create(QObject *parent) { return new QFseventsFileSystemWatcherEngine(parent); @@ -264,6 +296,7 @@ QFseventsFileSystemWatcherEngine *QFseventsFileSystemWatcherEngine::create(QObje QFseventsFileSystemWatcherEngine::QFseventsFileSystemWatcherEngine(QObject *parent) : QFileSystemWatcherEngine(parent) , stream(0) + , lastReceivedEvent(kFSEventStreamEventIdSinceNow) { // We cannot use signal-to-signal queued connections, because the @@ -272,6 +305,8 @@ QFseventsFileSystemWatcherEngine::QFseventsFileSystemWatcherEngine(QObject *pare this, SLOT(doEmitDirectoryChanged(const QString, bool)), Qt::QueuedConnection); connect(this, SIGNAL(emitFileChanged(const QString, bool)), this, SLOT(doEmitFileChanged(const QString, bool)), Qt::QueuedConnection); + connect(this, SIGNAL(scheduleStreamRestart()), + this, SLOT(restartStream()), Qt::QueuedConnection); queue = dispatch_queue_create("org.qt-project.QFseventsFileSystemWatcherEngine", NULL); } @@ -284,7 +319,7 @@ QFseventsFileSystemWatcherEngine::~QFseventsFileSystemWatcherEngine() // The assumption with the locking strategy is that this class cannot and will not be subclassed! QMutexLocker locker(&lock); - stopStream(); + stopStream(true); dispatch_release(queue); } @@ -292,12 +327,14 @@ QStringList QFseventsFileSystemWatcherEngine::addPaths(const QStringList &paths, QStringList *files, QStringList *directories) { - if (stream) + if (stream) { + DEBUG("Flushing, last id is %llu", FSEventStreamGetLatestEventId(stream)); FSEventStreamFlushSync(stream); + } QMutexLocker locker(&lock); - bool newWatchPathsFound = false; + bool needsRestart = false; QStringList p = paths; QMutableListIterator<QString> it(p); @@ -343,8 +380,9 @@ QStringList QFseventsFileSystemWatcherEngine::addPaths(const QStringList &paths, PathRefCounts::iterator it = watchedPaths.find(watchedPath); if (it == watchedPaths.end()) { - newWatchPathsFound = true; + needsRestart = true; watchedPaths.insert(watchedPath, 1); + DEBUG("Adding '%s' to watchedPaths", qPrintable(watchedPath)); } else { ++it.value(); } @@ -355,12 +393,14 @@ QStringList QFseventsFileSystemWatcherEngine::addPaths(const QStringList &paths, dirInfo.dirInfo = info; dirInfo.entries = scanForDirEntries(realPath); watchedDirectories.insert(realPath, dirInfo); + DEBUG("-- Also adding '%s' to watchedDirectories", qPrintable(realPath)); } else { watchedFiles[parentPath].insert(realPath, info); + DEBUG("-- Also adding '%s' to watchedFiles", qPrintable(realPath)); } } - if (newWatchPathsFound) { + if (needsRestart) { stopStream(); if (!startStream()) p = paths; @@ -375,6 +415,8 @@ QStringList QFseventsFileSystemWatcherEngine::removePaths(const QStringList &pat { QMutexLocker locker(&lock); + bool needsRestart = false; + QStringList p = paths; QMutableListIterator<QString> it(p); while (it.hasNext()) { @@ -389,10 +431,11 @@ QStringList QFseventsFileSystemWatcherEngine::removePaths(const QStringList &pat if (fi.isDir()) { DirsByName::iterator dirIt = watchedDirectories.find(realPath); if (dirIt != watchedDirectories.end()) { - derefPath(dirIt->dirInfo.watchedPath); + needsRestart |= derefPath(dirIt->dirInfo.watchedPath); watchedDirectories.erase(dirIt); directories->removeAll(origPath); it.remove(); + DEBUG("Removed directory '%s'", qPrintable(realPath)); } } else { QFileInfo fi(realPath); @@ -402,22 +445,32 @@ QStringList QFseventsFileSystemWatcherEngine::removePaths(const QStringList &pat InfoByName &filesInDir = pIt.value(); InfoByName::iterator fIt = filesInDir.find(realPath); if (fIt != filesInDir.end()) { - derefPath(fIt->watchedPath); + needsRestart |= derefPath(fIt->watchedPath); filesInDir.erase(fIt); if (filesInDir.isEmpty()) watchedFiles.erase(pIt); files->removeAll(origPath); it.remove(); + DEBUG("Removed file '%s'", qPrintable(realPath)); } } } } + locker.unlock(); + + if (needsRestart) + restartStream(); + return p; } bool QFseventsFileSystemWatcherEngine::startStream() { + Q_ASSERT(stream == 0); + if (stream) // This shouldn't happen, but let's be nice and handle it. + stopStream(); + if (watchedPaths.isEmpty()) return false; @@ -437,11 +490,15 @@ bool QFseventsFileSystemWatcherEngine::startStream() const CFAbsoluteTime latency = .5; // in seconds FSEventStreamCreateFlags flags = kFSEventStreamCreateFlagWatchRoot; + // Never start with kFSEventStreamEventIdSinceNow, because this will generate an invalid + // soft-assert in FSEventStreamFlushSync in CarbonCore when no event occurred. + if (lastReceivedEvent == kFSEventStreamEventIdSinceNow) + lastReceivedEvent = FSEventsGetCurrentEventId(); stream = FSEventStreamCreate(NULL, &callBackFunction, &callBackInfo, reinterpret_cast<CFArrayRef>(pathsToWatch), - kFSEventStreamEventIdSinceNow, + lastReceivedEvent, latency, flags); @@ -453,10 +510,13 @@ bool QFseventsFileSystemWatcherEngine::startStream() FSEventStreamSetDispatchQueue(stream, queue); if (FSEventStreamStart(stream)) { - DEBUG() << "Stream started successfully."; + DEBUG() << "Stream started successfully with sinceWhen =" << lastReceivedEvent; return true; } else { DEBUG() << "Stream failed to start!"; + FSEventStreamInvalidate(stream); + FSEventStreamRelease(stream); + stream = 0; return false; } } @@ -469,7 +529,7 @@ void QFseventsFileSystemWatcherEngine::stopStream(bool isStopped) FSEventStreamInvalidate(stream); FSEventStreamRelease(stream); stream = 0; - DEBUG() << "Stream stopped."; + DEBUG() << "Stream stopped. Last event ID:" << lastReceivedEvent; } } @@ -490,16 +550,16 @@ QFseventsFileSystemWatcherEngine::InfoByName QFseventsFileSystemWatcherEngine::s return entries; } -void QFseventsFileSystemWatcherEngine::derefPath(const QString &watchedPath) +bool QFseventsFileSystemWatcherEngine::derefPath(const QString &watchedPath) { PathRefCounts::iterator it = watchedPaths.find(watchedPath); - if (it == watchedPaths.end()) - return; - if (--it.value() < 1) { + if (it != watchedPaths.end() && --it.value() < 1) { watchedPaths.erase(it); - stopStream(); - startStream(); + DEBUG("Removing '%s' from watchedPaths.", qPrintable(watchedPath)); + return true; } + + return false; } #endif //QT_NO_FILESYSTEMWATCHER diff --git a/src/corelib/io/qfilesystemwatcher_fsevents_p.h b/src/corelib/io/qfilesystemwatcher_fsevents_p.h index c899c556c8..2de2bf4f18 100644 --- a/src/corelib/io/qfilesystemwatcher_fsevents_p.h +++ b/src/corelib/io/qfilesystemwatcher_fsevents_p.h @@ -84,10 +84,12 @@ public: Q_SIGNALS: void emitFileChanged(const QString path, bool removed); void emitDirectoryChanged(const QString path, bool removed); + void scheduleStreamRestart(); private slots: void doEmitFileChanged(const QString path, bool removed); void doEmitDirectoryChanged(const QString path, bool removed); + void restartStream(); private: struct Info { @@ -122,11 +124,11 @@ private: bool startStream(); void stopStream(bool isStopped = false); InfoByName scanForDirEntries(const QString &path); - void derefPath(const QString &watchedPath); - void checkDir(DirsByName::iterator &it); - void rescanDirs(const QString &path); - void rescanFiles(InfoByName &filesInPath); - void rescanFiles(const QString &path); + bool derefPath(const QString &watchedPath); + bool checkDir(DirsByName::iterator &it); + bool rescanDirs(const QString &path); + bool rescanFiles(InfoByName &filesInPath); + bool rescanFiles(const QString &path); QMutex lock; dispatch_queue_t queue; @@ -134,6 +136,7 @@ private: FilesByPath watchedFiles; DirsByName watchedDirectories; PathRefCounts watchedPaths; + FSEventStreamEventId lastReceivedEvent; }; QT_END_NAMESPACE diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 0406aeb501..321525ca18 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -2496,6 +2496,12 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, \snippet code/src_corelib_io_qsettings.cpp 7 + \li On Mac OS X, permissions to access settings not belonging to the + current user (i.e. SystemScope) have changed with 10.7 (Lion). Prior to + that version, users having admin rights could access these. For 10.7 and + 10.8 (Mountain Lion), only root can. However, 10.9 (Mavericks) changes + that rule again but only for the native format (plist files). + \li On Unix and Mac OS X systems, the advisory file locking is disabled if NFS (or AutoFS or CacheFS) is detected to work around a bug in the NFS fcntl() implementation, which hangs forever if statd or lockd aren't diff --git a/src/corelib/io/qsettings_mac.cpp b/src/corelib/io/qsettings_mac.cpp index 23cff6af27..7d1fb1a7c5 100644 --- a/src/corelib/io/qsettings_mac.cpp +++ b/src/corelib/io/qsettings_mac.cpp @@ -405,7 +405,6 @@ QMacSettingsPrivate::QMacSettingsPrivate(QSettings::Scope scope, const QString & } // if no bundle identifier yet. use a hard coded string. if (domainName.isEmpty()) { - setStatus(QSettings::AccessError); domainName = QLatin1String("unknown-organization.trolltech.com"); } @@ -540,27 +539,30 @@ void QMacSettingsPrivate::sync() // only report failures for the primary file (the one we write to) if (!ok && i == 0 && hostNames[j] == hostName && status == QSettings::NoError) { #if 1 - // work around what seems to be a bug in CFPreferences: - // don't report an error if there are no preferences for the application - QCFType<CFArrayRef> appIds = CFPreferencesCopyApplicationList(domains[i].userName, - hostNames[j]); - - // iterate through all the applications and see if we're there - CFIndex size = CFArrayGetCount(appIds); - for (CFIndex k = 0; k < size; ++k) { - const void *cfvalue = CFArrayGetValueAtIndex(appIds, k); - if (CFGetTypeID(cfvalue) == CFStringGetTypeID()) { - if (CFStringCompare(static_cast<CFStringRef>(cfvalue), - domains[i].applicationOrSuiteId, - kCFCompareCaseInsensitive) == kCFCompareEqualTo) { - setStatus(QSettings::AccessError); - break; + if (QSysInfo::macVersion() < QSysInfo::MV_10_7) { + // work around what seems to be a bug in CFPreferences: + // don't report an error if there are no preferences for the application + QCFType<CFArrayRef> appIds = CFPreferencesCopyApplicationList(domains[i].userName, + hostNames[j]); + + // iterate through all the applications and see if we're there + CFIndex size = CFArrayGetCount(appIds); + for (CFIndex k = 0; k < size; ++k) { + const void *cfvalue = CFArrayGetValueAtIndex(appIds, k); + if (CFGetTypeID(cfvalue) == CFStringGetTypeID()) { + if (CFStringCompare(static_cast<CFStringRef>(cfvalue), + domains[i].applicationOrSuiteId, + kCFCompareCaseInsensitive) == kCFCompareEqualTo) { + setStatus(QSettings::AccessError); + break; + } } } - } -#else - setStatus(QSettings::AccessError); + } else #endif + { + setStatus(QSettings::AccessError); + } } } } diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp index a0344a0206..062ab49207 100644 --- a/src/corelib/io/qstandardpaths_win.cpp +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -49,6 +49,10 @@ #include <qcoreapplication.h> #endif +#if !defined(Q_OS_WINCE) +const GUID qCLSID_FOLDERID_Downloads = { 0x374de290, 0x123f, 0x4565, { 0x91, 0x64, 0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b } }; +#endif + #include <qt_windows.h> #include <shlobj.h> #if !defined(Q_OS_WINCE) @@ -68,6 +72,10 @@ QT_BEGIN_NAMESPACE +#if !defined(Q_OS_WINCE) +typedef HRESULT (WINAPI *GetKnownFolderPath)(const GUID&, DWORD, HANDLE, LPWSTR*); +#endif + static QString convertCharArray(const wchar_t *path) { return QDir::fromNativeSeparators(QString::fromWCharArray(path)); @@ -77,6 +85,10 @@ QString QStandardPaths::writableLocation(StandardLocation type) { QString result; +#if !defined(Q_OS_WINCE) + static GetKnownFolderPath SHGetKnownFolderPath = (GetKnownFolderPath)QSystemLibrary::resolve(QLatin1String("shell32"), "SHGetKnownFolderPath"); +#endif + wchar_t path[MAX_PATH]; switch (type) { @@ -107,7 +119,18 @@ QString QStandardPaths::writableLocation(StandardLocation type) result = convertCharArray(path); break; - case DownloadLocation: // TODO implement with SHGetKnownFolderPath(FOLDERID_Downloads) (starting from Vista) + case DownloadLocation: +#if !defined(Q_OS_WINCE) + if (SHGetKnownFolderPath) { + LPWSTR path; + if (SHGetKnownFolderPath(qCLSID_FOLDERID_Downloads, 0, 0, &path) == S_OK) { + result = convertCharArray(path); + CoTaskMemFree(path); + } + break; + } +#endif + // fall through case DocumentsLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_PERSONAL, FALSE)) result = convertCharArray(path); |