Opened 11 years ago
Last modified 4 years ago
#6813 new Bugs
canonical function converts root-directory separator from '\' to '/' on Windows
Reported by: | Owned by: | Beman Dawes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | filesystem |
Version: | Boost 1.49.0 | Severity: | Problem |
Keywords: | canonical | Cc: |
Description
boost::filesystem::canonical reverses the path separator on rooted paths
Consider the following line:
boost::filesystem::path convertedPath = boost::filesystem::canonical("C:\\Foo\\Bar\\..\\Bar\\Baz");
On Windows, convertedPath is set to "C:/Foo\Bar\Baz", where I would expect it to be set to "C:\Foo\Bar\Baz"
The documentation states: "Returns: A canonical path that refers to the same file system object as absolute(p,base)."
If the input path has no symbolic links, 'dot' directories, or 'dot-dot' directories, then I would expect the output to match a call to boost::filesystem::absolute.
For example:
boost::filesystem::path canonicalPath = boost::filesystem::canonical("Bar\\Baz", "C:\\Foo"); boost::filesystem::path absolutePath = boost::filesystem::absolute("Bar\\Baz", "C:\\Foo");
canonicalPath is set to "C:/Foo\Bar\Baz", while absolutePath is set to "C:\Foo\Bar\Baz".
Looking at the implementation, this is related to the issue in ticket 5989 (https://svn.boost.org/trac/boost/ticket/5989). I agree with the sentiments in that ticket, but if the behavior of the path iterator will not be changing, then I think the canonical function should be updated to preseve path consistency in Windows.
This is also a general problem if you try to iterate over a path and reconstruct it with operator/. For example, if you have the following code:
The result for finalPath is going to be "C:/Foo\Bar\Baz". One way to solve this problem with keeping the iterator behavior the same is to always convert path separators to the preferred separator when appending paths.