@@ -111,25 +111,25 @@ WatcherThread::WatchChanges WatcherThread::watchChanges(size_t fileNotifyBufferS
111111
112112void WatcherThread::processEntries (FILE_NOTIFY_INFORMATION *curEntry)
113113{
114+ if (!curEntry) {
115+ return ;
116+ }
114117 QSet<QString> paths;
115118 const size_t fileNameBufferSize = 4096 ;
116119 wchar_t fileNameBuffer[fileNameBufferSize];
117- while (curEntry) {
118- const int len = curEntry->FileNameLength / sizeof ( wchar_t );
119- QString longfile = _longPath + QString::fromWCharArray (curEntry->FileName , len );
120+ do {
121+ const auto action = static_cast <FolderWatcherPrivate::ChangeAction>( curEntry->Action );
122+ QString longfile = _longPath + QString::fromWCharArray (curEntry->FileName , curEntry-> FileNameLength / sizeof ( wchar_t ) );
120123
121124 // Unless the file was removed or renamed, get its full long name
122125 // TODO: We could still try expanding the path in the tricky cases...
123- bool skip = false ;
124- const auto action = static_cast <FolderWatcherPrivate::ChangeAction>(curEntry->Action );
125126 if (action != FolderWatcherPrivate::ChangeAction::ACTION_REMOVED && action != FolderWatcherPrivate::ChangeAction::ACTION_RENAMED_OLD_NAME ) {
126127 const int longNameSize = GetLongPathNameW (reinterpret_cast <const wchar_t *>(longfile.utf16 ()), fileNameBuffer, fileNameBufferSize);
127128 const auto error = GetLastError ();
128129 if (longNameSize > 0 ) {
129130 longfile = QString::fromWCharArray (fileNameBuffer, longNameSize);
130131 } else {
131132 if (error == ERROR_FILE_NOT_FOUND ) {
132- skip = true ;
133133 qCInfo (lcFolderWatcher) << " Ignoring change in" << longfile << " the file no longer exists, probably a temporary file." << action;
134134 continue ;
135135 } else {
@@ -139,25 +139,17 @@ void WatcherThread::processEntries(FILE_NOTIFY_INFORMATION *curEntry)
139139 }
140140 }
141141
142- if (!skip) {
143- longfile = QDir::cleanPath (longfile);
144-
145- // Skip modifications of folders: One of these is triggered for changes
146- // and new files in a folder, probably because of the folder's mtime
147- // changing. We don't need them.
148- skip = action == FolderWatcherPrivate::ChangeAction::ACTION_MODIFIED && QFileInfo (longfile).isDir ();
149-
150- if (!skip) {
151- paths.insert (longfile);
152- }
153- }
154-
155- if (curEntry->NextEntryOffset == 0 ) {
156- break ;
142+ longfile = QDir::cleanPath (longfile);
143+ // Skip modifications of folders: One of these is triggered for changes
144+ // and new files in a folder, probably because of the folder's mtime
145+ // changing. We don't need them.
146+ if (action == FolderWatcherPrivate::ChangeAction::ACTION_MODIFIED && QFileInfo (longfile).isDir ()) {
147+ continue ;
157148 }
149+ paths.insert (longfile);
150+ } while (curEntry->NextEntryOffset != 0
158151 // FILE_NOTIFY_INFORMATION has no fixed size and the offset is in bytes therefor we first need to cast to char
159- curEntry = reinterpret_cast <FILE_NOTIFY_INFORMATION *>(reinterpret_cast <char *>(curEntry) + curEntry->NextEntryOffset );
160- }
152+ && (curEntry = reinterpret_cast <FILE_NOTIFY_INFORMATION *>(reinterpret_cast <char *>(curEntry) + curEntry->NextEntryOffset )));
161153 if (!paths.isEmpty ()) {
162154 Q_EMIT changed (paths);
163155 }
0 commit comments