QFileSystemWatcher/win: watch also for attribute changes of directories
The windows filesystemwatcher did not watch for attribute changes for directories (e.g. hidden flag) so it was not in sync with other backends. Fix it by adding FILE_NOTIFY_CHANGE_ATTRIBUTES to the watch flags when watching a directory. [ChangeLog][QtCore][QFileSystemWatcher] Fixed a bug that caused QFSW not to watch for attribute changes on Windows. Now it will correctly report when files and directories become hidden or unhidden, for example. Fixes: QTBUG-80545 Change-Id: I31767a0da899963e3940b4f5b36d1d581e6aa57c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
1c75f59588
commit
efff8ff57a
@ -403,6 +403,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths,
|
||||
const QString absolutePath = isDir ? fileInfo.absoluteFilePath() : fileInfo.absolutePath();
|
||||
const uint flags = isDir
|
||||
? (FILE_NOTIFY_CHANGE_DIR_NAME
|
||||
| FILE_NOTIFY_CHANGE_ATTRIBUTES
|
||||
| FILE_NOTIFY_CHANGE_FILE_NAME)
|
||||
: (FILE_NOTIFY_CHANGE_DIR_NAME
|
||||
| FILE_NOTIFY_CHANGE_FILE_NAME
|
||||
|
@ -34,6 +34,9 @@
|
||||
#include <QElapsedTimer>
|
||||
#include <QTextStream>
|
||||
#include <QDir>
|
||||
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
/* All tests need to run in temporary directories not used
|
||||
* by the application to avoid non-deterministic failures on Windows
|
||||
@ -79,6 +82,9 @@ private slots:
|
||||
void signalsEmittedAfterFileMoved();
|
||||
|
||||
void watchUnicodeCharacters();
|
||||
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
|
||||
void watchDirectoryAttributeChanges();
|
||||
#endif
|
||||
|
||||
private:
|
||||
QString m_tempDirPattern;
|
||||
@ -813,5 +819,27 @@ void tst_QFileSystemWatcher::watchUnicodeCharacters()
|
||||
QTRY_COMPARE(changedSpy.count(), 1);
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
|
||||
void tst_QFileSystemWatcher::watchDirectoryAttributeChanges()
|
||||
{
|
||||
QTemporaryDir temporaryDirectory(m_tempDirPattern);
|
||||
QVERIFY2(temporaryDirectory.isValid(), qPrintable(temporaryDirectory.errorString()));
|
||||
|
||||
QDir testDir(temporaryDirectory.path());
|
||||
const QString subDir(QString::fromLatin1("attrib_test"));
|
||||
QVERIFY(testDir.mkdir(subDir));
|
||||
testDir = QDir(temporaryDirectory.path() + QDir::separator() + subDir);
|
||||
|
||||
QFileSystemWatcher watcher;
|
||||
QVERIFY(watcher.addPath(temporaryDirectory.path()));
|
||||
FileSystemWatcherSpy changedSpy(&watcher, FileSystemWatcherSpy::SpyOnDirectoryChanged);
|
||||
QCOMPARE(changedSpy.count(), 0);
|
||||
QVERIFY(SetFileAttributes(reinterpret_cast<LPCWSTR>(testDir.absolutePath().utf16()), FILE_ATTRIBUTE_HIDDEN) != 0);
|
||||
QTRY_COMPARE(changedSpy.count(), 1);
|
||||
QVERIFY(SetFileAttributes(reinterpret_cast<LPCWSTR>(testDir.absolutePath().utf16()), FILE_ATTRIBUTE_NORMAL) != 0);
|
||||
QTRY_COMPARE(changedSpy.count(), 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
QTEST_MAIN(tst_QFileSystemWatcher)
|
||||
#include "tst_qfilesystemwatcher.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user