From 40e3c1c2b10401120d7c20d29d0d4a1ec00157a8 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Thu, 12 May 2022 14:15:55 +0200 Subject: [PATCH] Fix removal of trailing slash The fsevents implementation of QFileSystemWatcher on Mac OS X tries to remove trailing slashes from the paths when calling addPaths(). If the user tries to watch "/", the path is changed to "". The fix checks whether the path is longer than 1 before removing trailing slashes. Change-Id: Iafb10e449c4f3bd600b02edbe7c549911db05048 Reviewed-by: Thiago Macieira --- src/corelib/io/qfilesystemwatcher_fsevents.mm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/corelib/io/qfilesystemwatcher_fsevents.mm b/src/corelib/io/qfilesystemwatcher_fsevents.mm index b6d285cec3b..9a017a769fc 100644 --- a/src/corelib/io/qfilesystemwatcher_fsevents.mm +++ b/src/corelib/io/qfilesystemwatcher_fsevents.mm @@ -217,8 +217,8 @@ void QFseventsFileSystemWatcherEngine::processEvent(ConstFSEventStreamRef stream lastReceivedEvent = qMax(lastReceivedEvent, eventIds[i]); QString path = QFile::decodeName(eventPaths[i]); - if (path.endsWith(QDir::separator())) - path = path.mid(0, path.size() - 1); + if (path.size() > 1 && path.endsWith(QDir::separator())) + path.chop(1); if (eFlags & kFSEventStreamEventFlagMustScanSubDirs) { DEBUG("\tmust rescan directory because of coalesced events"); @@ -346,8 +346,8 @@ QStringList QFseventsFileSystemWatcherEngine::addPaths(const QStringList &paths, auto sg = qScopeGuard([&]{ unhandled.push_back(path); }); QString origPath = path.normalized(QString::NormalizationForm_C); QString realPath = origPath; - if (realPath.endsWith(QDir::separator())) - realPath = realPath.mid(0, realPath.size() - 1); + if (realPath.size() > 1 && realPath.endsWith(QDir::separator())) + realPath.chop(1); QString watchedPath, parentPath; realPath = QFileInfo(realPath).canonicalFilePath(); @@ -437,8 +437,8 @@ QStringList QFseventsFileSystemWatcherEngine::removePaths(const QStringList &pat for (const QString &origPath : paths) { auto sg = qScopeGuard([&]{ unhandled.push_back(origPath); }); QString realPath = origPath; - if (realPath.endsWith(QDir::separator())) - realPath = realPath.mid(0, realPath.size() - 1); + if (realPath.size() > 1 && realPath.endsWith(QDir::separator())) + realPath.chop(1); QFileInfo fi(realPath); realPath = fi.canonicalFilePath();