Details
-
Bug
-
Resolution: Invalid
-
P3: Somewhat important
-
None
-
4.6.2, 5.0.0
-
None
Description
Here is some strace output while using a file watcher.
First, I touch the file.
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}], 2, -1) = 1 ([{fd=5, revents=POLLIN}]) ioctl(5, FIONREAD, [16]) = 0 read(5, "\1\0\0\0\4\0\0\0\0\0\0\0\0\0\0\0", 16) = 16 write(2, "\"tst.cpp\" \n", 11"tst.cpp" ) = 11
Then I use an editor (vi, gedit, probably most others) to save the file.
poll([{fd=3, events=POLLIN}, {fd=5, events=POLLIN}], 2, -1) = 1 ([{fd=5, revents=POLLIN}]) ioctl(5, FIONREAD, [48]) = 0 read(5, "\1\0\0\0\4\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\4\0\0\0\0\0\0\0\0\0\0"..., 48) = 48 inotify_rm_watch(5, 1) = -1 EINVAL (Invalid argument) write(2, "\"tst.cpp\" \n", 11"tst.cpp" ) = 11
The same thing happens when I do "mv file tst.cpp". This is the 'atomic rename' pattern used in most editors when saving file contents.
It seems QFileSystemWatcher stops watching the file in this case. It does fire it's signal one last time so a workaround is to continuously re-add the file:
void MyObject::fileChanged(const QString &path) { watcher->addPath(path); // in case it was saved using 'atomic rename' ... }
Shouldn't QFileSystemWatcher just detect the 'atomic rename' case and continue to watch the file? If not, shouldn't the documentation warn users of the class about this problem?
Attachments
Issue Links
- duplicates
-
QTBUG-19350 QFileSystemWatcher unwatches file
- Closed
- is duplicated by
-
QTBUG-72227 QFileSystemWatcher reacts only once on file change
- Reported
-
QTBUG-46431 signal QFileSystemWatcher::fileChanged is no more emitted after 1 or 2 modifications of the file
- Closed
- relates to
-
QTBUG-46483 Doc unclear for the QFileSystemWatcher
- Closed
- resulted in
-
QTBUG-71768 qmlpreview command line client fails to track replaced files
- Closed
-
QTBUG-53607 QFileSystemWatcher: add note about gedit and vim
- Closed