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

QFileSystemWatcher wrong reaction on file rename

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Won't Do
    • Affects Version/s: 5.4.1
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      linux 3.19.3

      Description

      QFileSystemWatchers reaction to a file rename is weird.

      What it does:
      If a watched dir 'A' gets renamed to e.g. 'B', following directoryChanged signals report 'A' instead of the new name. The list of watched directories is reports 'A' but not 'B'.

      What it shoulf do:
      If a watched dir 'A' gets renamed to e.g. 'B', following directoryChanged signals report 'B'. The list of watched directories is reports 'B' as watched.

      See the following or download the attachment.

          QDir d = QDir::temp();
          d.mkpath("TEST/A");
          qDebug() << "mkdir " << d.absoluteFilePath("TEST/A");
          d.rmpath("TEST/B"); // For multiple runs
          d.rmpath("TEST/C/D"); // For multiple runs
      
          QFileSystemWatcher fsw;
          fsw.addPath(d.absoluteFilePath("TEST"));
          fsw.addPath(d.absoluteFilePath("TEST/A"));
          QObject::connect(&fsw, &QFileSystemWatcher::directoryChanged,
                           [&](const QString & path){
              qDebug() << "\ndirectoryChanged:" << path;
              qDebug() << "-> directories" << fsw.directories();
          });
      
          QObject::connect(&fsw, &QFileSystemWatcher::fileChanged,
                           [&](const QString & path){
              qDebug() << "\nFILE!!!!!!!:" << path;
          });
      
          QTimer::singleShot(1000, [&](){
              qDebug() << "\nRename A to B";
              d.rename("TEST/A","TEST/B");
              qDebug() << "-> directories" << fsw.directories();
            });
      
          QTimer::singleShot(2000, [&](){
              qDebug() << "\nAdd dir C in B";
              d.mkpath("TEST/B/C");
              qDebug() << "-> directories" << fsw.directories();
            });
      
          QTimer::singleShot(3000, [&](){
              qDebug() << "\nRemove dir C in B";
              d.rmdir("TEST/B/C");
              qDebug() << "-> directories" << fsw.directories();
            });
      
          QTimer::singleShot(4000, [&](){
              qDebug() << "\nRemove dir B";
              d.rmdir("TEST/B");
              qDebug()  << "-> directories"<< fsw.directories();
            });
      
          QTimer::singleShot(5000, [&](){
              qDebug() << "\nRemove dir TEST";
              d.rmdir("TEST/");
              qDebug()  << "-> directories"<< fsw.directories();
            });
      

      Produces this output:

      mkdir  "/tmp/TEST/A"
      
      Rename A to B
      -> directories ("/tmp/TEST", "/tmp/TEST/A")  # this may still be okay 
      
      directoryChanged: "/tmp/TEST"
      -> directories ("/tmp/TEST", "/tmp/TEST/A")  # this and the following not
      
      Add dir C in B
      -> directories ("/tmp/TEST", "/tmp/TEST/A") # <<<
      
      directoryChanged: "/tmp/TEST/A" # <<<
      -> directories ("/tmp/TEST", "/tmp/TEST/A") # <<<
      
      Remove dir C in B
      -> directories ("/tmp/TEST", "/tmp/TEST/A") # <<<
      
      directoryChanged: "/tmp/TEST/A"
      -> directories ("/tmp/TEST", "/tmp/TEST/A") # <<<
      
      Remove dir B
      -> directories ("/tmp/TEST", "/tmp/TEST/A") # <<<
      
      directoryChanged: "/tmp/TEST/A" # <<<
      -> directories ("/tmp/TEST")
      
      directoryChanged: "/tmp/TEST"
      -> directories ("/tmp/TEST")
      
      Remove dir TEST
      -> directories ("/tmp/TEST")
      
      directoryChanged: "/tmp/TEST"
      -> directories ()}}
      

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              thiago Thiago Macieira
              Reporter:
              manuelschneid3r Manuel Schneider
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes