|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63529 - in trunk/libs/filesystem/v3: doc src test
From: bdawes_at_[hidden]
Date: 2010-07-02 15:30:54
Author: bemandawes
Date: 2010-07-02 15:30:49 EDT (Fri, 02 Jul 2010)
New Revision: 63529
URL: http://svn.boost.org/trac/boost/changeset/63529
Log:
Network paths have root names even on POSIX
Text files modified:
trunk/libs/filesystem/v3/doc/reference.html | 11 ++----
trunk/libs/filesystem/v3/src/operations.cpp | 62 +++++++++++++++++++++++++++++++--------
trunk/libs/filesystem/v3/test/operations_test.cpp | 6 +-
3 files changed, 56 insertions(+), 23 deletions(-)
Modified: trunk/libs/filesystem/v3/doc/reference.html
==============================================================================
--- trunk/libs/filesystem/v3/doc/reference.html (original)
+++ trunk/libs/filesystem/v3/doc/reference.html 2010-07-02 15:30:49 EDT (Fri, 02 Jul 2010)
@@ -1832,8 +1832,7 @@
<h4><a name="Function-specifications">Operational function specifications</a></h4>
<pre>path <a name="absolute">absolute</a>(const path& p, const path& base=current_path());</pre>
<blockquote>
- <p><i>Returns:</i> If <code>p.is_empty() || p.is_absolute()</code>, returns
- <code>p</code>. Otherwise returns a path composed according to to the
+ <p><i>Returns:</i> A path composed according to to the
following table</p>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#111111" style="border-collapse: collapse">
<tr>
@@ -1857,10 +1856,8 @@
</table>
<p><i>Postconditions:</i> For the returned path, <code>rp,</code> <code>
rp.is_absolute()</code> is true.</p>
- <p>[<i><a name="complete_note">Note</a>:</i> On POSIX-like systems, the return
- is effectively <code>p.is_empty() || p.is_absolute() ? p : absolute(base) / p</code> <i>--
- end note</i>]</p>
- <p><i>Throws:</i> If <code>base.is_absolute()</code> is true, throws nothing.</p>
+ <p><i>Throws:</i> If <code>base.is_absolute()</code> is true, throws only if
+ memory allocation fails.</p>
</blockquote>
<pre>void copy_file(const path& from, const path& to);</pre>
<blockquote>
@@ -3055,7 +3052,7 @@
<p>Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
<p>Revised
-<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->01 July 2010<!--webbot bot="Timestamp" endspan i-checksum="18760" --></p>
+<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->02 July 2010<!--webbot bot="Timestamp" endspan i-checksum="18762" --></p>
</body>
Modified: trunk/libs/filesystem/v3/src/operations.cpp
==============================================================================
--- trunk/libs/filesystem/v3/src/operations.cpp (original)
+++ trunk/libs/filesystem/v3/src/operations.cpp 2010-07-02 15:30:49 EDT (Fri, 02 Jul 2010)
@@ -583,20 +583,56 @@
BOOST_FILESYSTEM_DECL
path absolute(const path& p, const path& base)
{
- if ( p.empty() || p.is_absolute() )
- return p;
- // recursively calling absolute is sub-optimal, but is simple
+// if ( p.empty() || p.is_absolute() )
+// return p;
+// // recursively calling absolute is sub-optimal, but is simple
+// path abs_base(base.is_absolute() ? base : absolute(base));
+//# ifdef BOOST_WINDOWS_API
+// if (p.has_root_directory())
+// return abs_base.root_name() / p;
+// // !p.has_root_directory
+// if (p.has_root_name())
+// return p.root_name()
+// / abs_base.root_directory() / abs_base.relative_path() / p.relative_path();
+// // !p.has_root_name()
+//# endif
+// return abs_base / p;
+
+ // recursively calling absolute is sub-optimal, but is sure and simple
path abs_base(base.is_absolute() ? base : absolute(base));
-# ifdef BOOST_WINDOWS_API
- if (p.has_root_directory())
- return abs_base.root_name() / p;
- // !p.has_root_directory
- if (p.has_root_name())
- return p.root_name()
- / abs_base.root_directory() / abs_base.relative_path() / p.relative_path();
- // !p.has_root_name()
-# endif
- return abs_base / p;
+
+ // store expensive to compute values that are needed multiple times
+ path p_root_name (p.root_name());
+ path base_root_name (abs_base.root_name());
+ path p_root_directory (p.root_directory());
+
+ if (p.empty())
+ return abs_base;
+
+ if (!p_root_name.empty()) // p.has_root_name()
+ {
+ if (p_root_directory.empty()) // !p.has_root_directory()
+ return p_root_name / abs_base.root_directory()
+ / abs_base.relative_path() / p.relative_path();
+ // p is absolute, so fall through to return p at end of block
+ }
+
+ else if (!p_root_directory.empty()) // p.has_root_directory()
+ {
+# ifdef BOOST_POSIX_API
+ // POSIX can have root name it it is a network path
+ if (base_root_name.empty()) // !abs_base.has_root_name()
+ return p;
+# endif
+ return base_root_name / p;
+ }
+
+ else
+ {
+ return abs_base / p;
+ }
+
+ return p; // p.is_absolute() is true
}
namespace detail
Modified: trunk/libs/filesystem/v3/test/operations_test.cpp
==============================================================================
--- trunk/libs/filesystem/v3/test/operations_test.cpp (original)
+++ trunk/libs/filesystem/v3/test/operations_test.cpp 2010-07-02 15:30:49 EDT (Fri, 02 Jul 2010)
@@ -979,7 +979,7 @@
{
std::cout << "absolute_tests..." << std::endl;
- BOOST_TEST(fs::absolute("").empty());
+ BOOST_TEST_EQ(fs::absolute(""), fs::current_path() );
BOOST_TEST_EQ(fs::absolute(fs::current_path() / "foo/bar"), fs::current_path() / "foo/bar");
BOOST_TEST_EQ(fs::absolute("foo"), fs::current_path() / "foo");
BOOST_TEST_EQ(fs::absolute("foo", fs::current_path()), fs::current_path() / "foo");
@@ -993,10 +993,10 @@
// these tests were moved from elsewhere, so may duplicate some of the above tests
// p.empty()
- BOOST_TEST_EQ(fs::absolute(fs::path(), "//foo/bar"), "");
+ BOOST_TEST_EQ(fs::absolute(fs::path(), "//foo/bar"), "//foo/bar");
if (platform == "Windows")
{
- BOOST_TEST_EQ(fs::absolute(fs::path(), "a:/bar"), "");
+ BOOST_TEST_EQ(fs::absolute(fs::path(), "a:/bar"), "a:/bar");
}
// p.has_root_name()
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk