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

QFileSystemWatcher fails to emit 'modified' on special characters

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 5.5.1
    • None
    • OSX 10.10.5 Qt 5.5.1 from git

    Description

      • Create a directory containing the ä character and run the program below:
      #include <QCoreApplication>
      #include <QFileSystemWatcher>
      #include <QDebug>
      #include <QFile>
      
      namespace {
      
      const auto dir = "/YOUR_PATH/Täst";
      
      class Watcher : public QFileSystemWatcher
      {
      public:
        Watcher()
        {
          connect(this, &QFileSystemWatcher::directoryChanged, this, [](const QString& dir) { qDebug()<<"dir changed:"<<dir; });
        }
      };
      
      }//< ns
      
      int main(int argc, char *argv[])
      {
        QCoreApplication a(argc, argv);
      
        Watcher w;
        qDebug()<<"add path success?"<<w.addPath(dir);
      
        return a.exec();
      }
      
      
      • Add/remove files into/from the created folder
      • You will not see "dir changed:" printed on modification

      Reason

      The folder path is added to the watcher's internal hash with one encoding (using QString::fromLocal8Bit), but when a change occurs, the folder to query is with different encoding (using QFile::decodeName), thus the hash fails to find a match as if the folder is not monitored at all.

      Workaround

      None! Even if someone adds a string with an explicit QFile::decodeName encoding, the string is always first "converted" by a QString::fromLocal8Bit call.

      Solution

      The path added must be with the exact same encoding as the one that is queried later.

      We must either fixup QFseventsFileSystemWatcherEngine::addPaths to explicitly store a QFile::decodeName path
      or
      Fix FileSystemEngine::canonicalName (used by QFileInfo::canonicalFilePath, used by QFseventsFileSystemWatcherEngine::addPaths) to use QFile::decodeName instead QString::fromLocal8Bit:

      /qt5/qtbase/src/corelib/io/qfilesystemengine_unix.cpp
      QFileSystemEngine::canonicalName
      line: 289:

      QString canonicalPath = QDir::cleanPath(/*QString::fromLocal8Bit*/QFile::decodeName(ret));
      

      This works

      Question: What is the difference b/w QString::fromLocal8Bit and QFile::decodeName? To what extend are interchangeable?

      Attachments

        Issue Links

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

          Activity

            People

              thiago Thiago Macieira
              mnaydenov Mihail Naydenov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes