@@ -86,19 +86,19 @@ void DirectoryWatcher::OnDirectoryChanged(const QString& path)
86
86
emit DirectoryChanged (path.toStdString ());
87
87
88
88
const QDir dir (path);
89
- const QFileInfoList watchedList = dir.entryInfoList (QDir::NoDotAndDotDot | QDir::Files);
89
+ const QFileInfoList files = dir.entryInfoList (QDir::NoDotAndDotDot | QDir::Files);
90
90
91
- std::unordered_set<QString> missing (m_lastModified.size ());
92
- for (const auto & file : m_lastModified | std::views::keys)
93
- missing.insert (file);
91
+ auto beforeFiles = m_lastModified | std::views::keys | std::views::filter ([&path](const QString& m) -> bool
92
+ {
93
+ return m.startsWith (path);
94
+ }) | std::ranges::to<std::unordered_set<QString>>();
94
95
95
- for (const QFileInfo& fileInfo : watchedList )
96
+ for (const QFileInfo& fileInfo : files )
96
97
{
97
- QString filePath = fileInfo.absoluteFilePath ();
98
- QDateTime lastModified = fileInfo.lastModified ();
98
+ const QString filePath = fileInfo.absoluteFilePath ();
99
+ const QDateTime lastModified = fileInfo.lastModified ();
99
100
100
- const bool contains = m_lastModified.contains (filePath);
101
- if (!contains || m_lastModified[filePath] < lastModified)
101
+ if (!m_lastModified.contains (filePath) || m_lastModified[filePath] < lastModified)
102
102
{
103
103
m_lastModified[filePath] = lastModified;
104
104
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
@@ -108,13 +108,15 @@ void DirectoryWatcher::OnDirectoryChanged(const QString& path)
108
108
#endif
109
109
}
110
110
111
- if (missing.contains (filePath))
111
+ // remove it from the list if it still exists
112
+ if (beforeFiles.contains (filePath))
112
113
{
113
- missing .erase (filePath);
114
+ beforeFiles .erase (filePath);
114
115
}
115
116
}
116
117
117
- for (const QString& file : missing)
118
+ // these files were removed
119
+ for (const QString& file : beforeFiles)
118
120
{
119
121
m_lastModified.erase (file);
120
122
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0 commit comments