Boost C++ Libraries: Ticket #6813: canonical function converts root-directory separator from '\' to '/' on Windows https://svn.boost.org/trac10/ticket/6813 <p> boost::filesystem::canonical reverses the path separator on rooted paths </p> <p> Consider the following line: </p> <pre class="wiki">boost::filesystem::path convertedPath = boost::filesystem::canonical("C:\\Foo\\Bar\\..\\Bar\\Baz"); </pre><p> On Windows, convertedPath is set to "C:/Foo\Bar\Baz", where I would expect it to be set to "C:\Foo\Bar\Baz" </p> <p> The documentation states: "Returns: A canonical path that refers to the same file system object as absolute(p,base)." </p> <p> 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. </p> <p> For example: </p> <pre class="wiki">boost::filesystem::path canonicalPath = boost::filesystem::canonical("Bar\\Baz", "C:\\Foo"); boost::filesystem::path absolutePath = boost::filesystem::absolute("Bar\\Baz", "C:\\Foo"); </pre><p> canonicalPath is set to "C:/Foo\Bar\Baz", while absolutePath is set to "C:\Foo\Bar\Baz". </p> <p> Looking at the implementation, this is related to the issue in ticket 5989 (<a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/5989"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/5989</a>). 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. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6813 Trac 1.4.3 Aaron Barany <akb825@…> Fri, 20 Apr 2012 22:49:30 GMT <link>https://svn.boost.org/trac10/ticket/6813#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6813#comment:1</guid> <description> <p> 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: </p> <div class="wiki-code"><div class="code"><pre><span class="n">boost</span><span class="o">::</span><span class="n">filesystem</span><span class="o">::</span><span class="n">path</span> <span class="n">path</span> <span class="o">=</span> <span class="s">&quot;C:</span><span class="se">\\</span><span class="s">Foo</span><span class="se">\\</span><span class="s">Bar</span><span class="se">\\</span><span class="s">Baz&quot;</span><span class="p">;</span> <span class="n">boost</span><span class="o">::</span><span class="n">filesystem</span><span class="o">::</span><span class="n">path</span> <span class="n">finalPath</span><span class="p">;</span> <span class="k">for</span> <span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">filesystem</span><span class="o">::</span><span class="n">path</span><span class="o">::</span><span class="n">iterator</span> <span class="n">iter</span> <span class="o">=</span> <span class="n">path</span><span class="p">.</span><span class="n">begin</span><span class="p">();</span> <span class="n">iter</span> <span class="o">!=</span> <span class="n">path</span><span class="p">.</span><span class="n">end</span><span class="p">();</span> <span class="o">++</span><span class="n">iter</span><span class="p">)</span> <span class="n">finalPath</span> <span class="o">/=</span> <span class="o">*</span><span class="n">iter</span><span class="p">;</span> </pre></div></div><p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 11 Jul 2018 07:27:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6813#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6813#comment:2</guid> <description> <p> Is there any update on it? </p> </description> <category>Ticket</category> </item> </channel> </rss>