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

QFileInfo::symLinkTarget() returns an incorrect path on a symlink for a shared folder on Windows

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4: Low
    • None
    • 5.11.1, 5.11.2
    • Core: I/O
    • None
    • Windows 10
    • Windows

    Description

      QFileInfo::symLinkTarget() returns an incorrect path on a symlink for a shared folder on WindowsQFileInfo::symLinkTarget() returns an incorrect path on a symlink for a shared folder on Windows
      On Windows 10, for a symbolic link created for a shared directory using "MKLINK /D", QFileInfo::symLinkTarget() returns an incorrect path. For a shortcut pointing to the symbolic link, QFileInfo::canonicalFilePath() / QFileInfo::canonicalPath() returns an incorrect path.
      Steps to reproduce:

      1. Create a directory named as "c:\test_shared". Put some directories and text file under the ‘test_shared’ directory.
      2. Make the ‘test_shared’ directory as a shared directory. Go to properties of ‘test_shared’ directory, Sharing tab, Click on ‘Share…’
      3. Now we will have a UNC path for ‘test_shared’ directory ( UNC Path: [ https://msdn.microsoft.com/en-us/library/cc227007.aspx|https://msdn.microsoft.com/en-us/library/cc227007.aspx] ). For example for a machine named ‘foo’, the UNC path for ‘test_shared’ is ‘//foo/test_shared’
      4. Create a symlink on "c:\" for ‘//foo/test_shared’. Open a command prompt, and run "MKLINK /D c:\link_to_share \\foo\test_shared"
      5. Create a shortcut on "c:\" to ‘link_to_share’. Right click on ‘link_to_share’ and select ‘Create shortcut’. This creates ‘c:\link_to_share – Shortcut’
      6. Then try the following code
           
            QString paths[2] = {
                QLatin1String("C:\\link_to_share"),
                QLatin1String("C:\\link_to_share - Shortcut.lnk")
            };
            QFileInfo info1(paths[0]); 
            qDebug() << info1.filePath() << info1.symLinkTarget();
            QFileInfo info2(paths[1]);
            qDebug() << info2.filePath() << info2.canonicalFilePath();
        

        Expected results:
        "C:/link_to_share" "//foo/test_shared"
        "C:/link_to_share - Shortcut.lnk" "//foo/test_shared"
        Output:   
        "C:/link_to_share" "C:/UNC/foo/test_shared"
        "C:/link_to_share - Shortcut.lnk" "C:/UNC/foo/test_shared"

      Attachments

        Issue Links

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

          Activity

            People

              dongmei Dongmei Wang
              dongmei Dongmei Wang
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes