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

QFile/QFileInfo function size() wrong for symlinks(WIN)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Won't Do
    • Affects Version/s: 4.8.0, 5.0.1, 5.1.1, 5.2.0, 5.3.1, 5.8.0
    • Fix Version/s: None
    • Component/s: Core: I/O
    • Environment:
      Windows 7, Qt 4.8.0, Qt 5.X
    • Commits:
      7ef398e8fa7e283bf42eacfa9f0a514f6490aad2

      Description

      qtbug64121_diag.diff The Documentation (QFileInfo Class Reference) states that:

      "On Windows, symlinks (shortcuts) are .lnk files. The reported size() is that of the symlink (not the link's target), and opening a symlink using QFile opens the .lnk file".

      But the returned size is that of the target file, not the symlink file!

      looking around in the source i found that in the file "qfilesystemengine_win.cpp" the function "QFileSystemEngine::fillMetaData" (l:808)
      calls readLink which gets the path of the target...
      This is wrong, it doesn't need to call readLink. Just use the symlink file path.
      If we want information about the target we can call symLinkTarget().

      line 808: change this

       
          QFileSystemEntry fname;
          data.knownFlagsMask |= QFileSystemMetaData::WinLnkType;
          if(entry.filePath().endsWith(QLatin1String(".lnk"))) {
              data.entryFlags |= QFileSystemMetaData::WinLnkType;
              fname = QFileSystemEntry(readLink(entry));
          } else {
              fname = entry;
          }
      

      to

       
          QFileSystemEntry fname;
          data.knownFlagsMask |= QFileSystemMetaData::WinLnkType;
          if(entry.filePath().endsWith(QLatin1String(".lnk"))) {
              data.entryFlags |= QFileSystemMetaData::WinLnkType;
          }
          fname = entry;
      

      I compiled Qt with this changes and now it works as expected.

        Attachments

        1. FileFunctions.cpp
          4 kB
        2. FileFunctions.h
          1.0 kB
        3. qtbug24831_win.diff
          1 kB
        4. qtbug24831.zip
          1 kB
        5. qtbug64121_diag.diff
          3 kB

          Issue Links

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

            Activity

              People

              Assignee:
              cnn Qt Core & Network
              Reporter:
              patricklx patrick pat
              Votes:
              12 Vote for this issue
              Watchers:
              17 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes