Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-24898

QFileSystemWatcher (inotify) and editors that rename files

    XMLWordPrintable

Details

    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

          Activity

            People

              thiago Thiago Macieira
              lramsay Lincoln Ramsay (closed Nokia identity) (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: