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

Possible discrepancies when handling a trailing path separator in QFileInfo canonicalPath and absolutePath.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.4
    • Core: I/O
    • None
    • Linux/Wayland

    Description

      When working with QFileInfo, a trailing separator in a path seems to affect `canonicalPath` and `absolutePath` differently.

      For example, consider some path `/home/luca/`, with a trailing separator.

      The following call will result in the string `/home`:

      QFileInfo("/home/luca/").canonicalPath()
      

      While the following call will result in the string `/home/luca`:

      QFileInfo("/home/luca/").absolutePath()
      

      Standing by the documentation, `canonicalPath`:

      Returns the file's path canonical path (excluding the file name), i.e. an absolute path without symbolic links or redundant "." or ".." elements.

      And `absolutePath`:

      Returns a file's path absolute path. This doesn't include the file name.[...]In contrast to canonicalPath() symbolic links or redundant "." or ".." elements are not necessarily removed

      I would generally expect those two methods to behave equally unless symbolic links or relative path elements such as ".." are present.

      Furthermore, considering the documentation for `path`:

      [...]Note that, if this QFileInfo object is given a path ending in a slash, the name of the file is considered empty and this function will return the entire path.

      I would expect the behavior that `canonicalPath` shows might be a bug as it is inconsistent with how other method in the same API treat trailing separators, while the one that `absolutePath` shows is the intended one.

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-100682
          # Subject Branch Project Status CR V

          Activity

            People

              thiago Thiago Macieira
              diseraluca Luca Di Sera
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change