Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58778 - in sandbox/filesystem-v3: boost/filesystem libs/filesystem/doc libs/filesystem/src libs/filesystem/test
From: bdawes_at_[hidden]
Date: 2010-01-06 14:23:34


Author: bemandawes
Date: 2010-01-06 14:23:33 EST (Wed, 06 Jan 2010)
New Revision: 58778
URL: http://svn.boost.org/trac/boost/changeset/58778

Log:
Special case path::stem() and extension() for "." and ".."
Text files modified:
   sandbox/filesystem-v3/boost/filesystem/operations.hpp | 36 ----------------
   sandbox/filesystem-v3/libs/filesystem/doc/do_list.html | 18 +++++++
   sandbox/filesystem-v3/libs/filesystem/doc/reference.html | 22 +++++----
   sandbox/filesystem-v3/libs/filesystem/src/operations.cpp | 16 +-----
   sandbox/filesystem-v3/libs/filesystem/src/path.cpp | 4 +
   sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp | 88 +++++++++++++++++++++++++--------------
   6 files changed, 93 insertions(+), 91 deletions(-)

Modified: sandbox/filesystem-v3/boost/filesystem/operations.hpp
==============================================================================
--- sandbox/filesystem-v3/boost/filesystem/operations.hpp (original)
+++ sandbox/filesystem-v3/boost/filesystem/operations.hpp 2010-01-06 14:23:33 EST (Wed, 06 Jan 2010)
@@ -11,22 +11,6 @@
 // Library home page: http://www.boost.org/libs/filesystem
 
 //--------------------------------------------------------------------------------------//
-/*
-* TODO List
-*
-* Review all operations.cpp code for race conditions similar to #2925. Fix or document.
-* Enable all BOOST_FILESYSTEM_NO_DEPRECATED code.
-* rename and remove really need to be renamed. If users says "using namespace boost::filesystem"
- and some header included stdio, there is just too much chance of silent error.
-* create_directories error handling.
-* Review any commented out code, both in operations.hpp and operations.cpp
-* Fold convenience.hpp into operations.hpp
-* Two argument recursive_directory_iterator ctor isn't recognizing throws().
- would it be better to fold into a single two argument ctor with default?
-* Add the push_directory class from tools/release/required_files.cpp
-
-*/
-//--------------------------------------------------------------------------------------//
 
 #ifndef BOOST_FILESYSTEM_OPERATIONS_HPP
 #define BOOST_FILESYSTEM_OPERATIONS_HPP
@@ -506,26 +490,6 @@
   file_status symlink_status() const {return m_get_symlink_status();}
   file_status symlink_status(system::error_code& ec) const {return m_get_symlink_status(&ec);}
 
- //// conversion simplifies the most common use of directory_entry
- // Removed; poor design and too likely to conflict with path v3 constructor templates
- //operator const boost::filesystem::path&() const { return m_path; }
-
-//# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
-// // deprecated functions preserve common use cases in legacy code
-// typename Path::string_type filename() const
-// {
-// return path().filename();
-// }
-// typename Path::string_type leaf() const
-// {
-// return path().filename();
-// }
-// typename Path::string_type string() const
-// {
-// return path().string();
-// }
-//# endif
-
 private:
   boost::filesystem::path m_path;
   mutable file_status m_status; // stat()-like

Modified: sandbox/filesystem-v3/libs/filesystem/doc/do_list.html
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/doc/do_list.html (original)
+++ sandbox/filesystem-v3/libs/filesystem/doc/do_list.html 2010-01-06 14:23:33 EST (Wed, 06 Jan 2010)
@@ -34,6 +34,7 @@
   tests for those cases, all decompositions. See test_decompositions() in
   path_unit_test.cpp.</li>
   <li style="font-size: 10pt">Add docs for scoped_path_locale.</li>
+ <li style="font-size: 10pt">Regenerate path decomposition table.</li>
 </ul>
 
 <h2>Code</h2>
@@ -51,7 +52,8 @@
   Features.</li>
   <li>Add test case: relational operators on paths differing only in trailing
   separator. Rationale?</li>
- <li>Provide the name check functions for more character types? Templatize?</li>
+ <li>Provide the name check functions for more character types? Templatize?
+ take a path argument?</li>
   <li style="font-size: 10pt">Add test for scoped_path_locale.</li>
   <li style="font-size: 10pt">Add codepage 936/950/etc test cases.</li>
   <li style="font-size: 10pt">Are generic versions of string(), native_string()
@@ -67,12 +69,24 @@
   <li style="font-size: 10pt">Should path iteration to a separator result in:<br>
   -- the actual separator used<br>
   -- the preferred separator<br>
- -- the generic separator &lt;-- makes it easier to write portable code</li>
+ -- the generic separator &lt;-- makes it easier to write portable code<br>
+ -- a dot</li>
 </ul>
 <h3>Operations</h3>
 <ul>
   <li>Would complete(), system_complete() be clearer if renamed absolute(),
   absolute_system() (or absolute_native())?</li>
+ <li>Review all operations.cpp code for race conditions similar to #2925. Fix
+ or document.</li>
+ <li>Enable all BOOST_FILESYSTEM_NO_DEPRECATED code.</li>
+ <li>rename and remove really need to be renamed. If users says &quot;using
+ namespace boost::filesystem&quot;<br>
+ and some header included stdio, there is just too much chance of silent error.</li>
+ <li>create_directories error handling needs work.</li>
+ <li>Fold convenience.hpp into operations.hpp</li>
+ <li>Two argument recursive_directory_iterator ctor isn't recognizing throws().
+ Would it be better to fold into a single two argument ctor with default?</li>
+ <li>Add the push_directory class from tools/release/required_files.cpp</li>
 </ul>
 
 </body>

Modified: sandbox/filesystem-v3/libs/filesystem/doc/reference.html
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/doc/reference.html (original)
+++ sandbox/filesystem-v3/libs/filesystem/doc/reference.html 2010-01-06 14:23:33 EST (Wed, 06 Jan 2010)
@@ -220,9 +220,10 @@
 If the file pointed to does not exist, the symbolic link is said to be a
 &quot;dangling&quot; symbolic link.<i> -- end note</i>]<i> </i></p>
 </blockquote>
-<p><b><i><a name="Slash">Slash</a>:</i></b> The character <tt>'/'</tt>, also known as
-solidus.</p>
-<p><b><i><a name="Dot">Dot</a>:</i></b> The character '.', also known as period.</p>
+<p><b><i><a name="Slash">Slash</a>:</i></b> The character <tt><code>'/'</code></tt>, also known as
+<i>solidus</i>.</p>
+<p><b><i><a name="Dot">Dot</a>:</i></b> The character <code>'.'</code>, also known as
+<i>period</i>.</p>
 <p><b><i><a name="Race-condition">Race condition</a>:</i></b> The condition that occurs
 when multiple threads, processes, or computers interleave access and
 modification of
@@ -1012,18 +1013,21 @@
 </blockquote>
 <pre>path stem(const path&amp; p) const;</pre>
 <blockquote>
- <p><i>Returns:</i> if <code>p.filename()</code> contains a <i>dot</i>, returns
+ <p><i>Returns:</i> if <code>p.filename()</code>contains a dot but does not
+ consist solely of one or to two dots, returns
   the substring of <code>p.filename()</code> starting at its beginning and
- ending at the last <i>dot</i> (the <i>dot</i> is not included). Otherwise,
+ ending at the last dot (the dot is not included). Otherwise,
   returns <code>
   p.filename()</code>.</p>
 </blockquote>
 <pre>path extension(const path&amp; p) const;</pre>
 <blockquote>
- <p><i>Returns:</i> if <code>p.filename()</code> contains a <i>dot</i>, returns
- the substring of <code>p.filename()</code> starting at the rightmost <i>dot</i>
- and ending at the string's end. Otherwise, returns an empty string. </p>
- <p>[<i>Note:<b> </b></i>The <i>dot</i> is included in the return value so that
+ <p><i>Returns:</i> if <code>p.filename()</code> contains a dot but does not
+ consist solely of one or to two dots, returns
+ the substring of <code>p.filename()</code> starting at the rightmost dot
+ and ending at the path's end. Otherwise, returns an empty <code>path</code>
+ object. </p>
+ <p>[<i>Note:<b> </b></i>The dot is included in the return value so that
   it is possible to distinguish between no extension and an empty extension.&nbsp; <i>-- end note</i>]</p>
   <p>Implementations are permitted but not required to define additional
   behavior for file systems which append additional elements to extensions, such

Modified: sandbox/filesystem-v3/libs/filesystem/src/operations.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/src/operations.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/src/operations.cpp 2010-01-06 14:23:33 EST (Wed, 06 Jan 2010)
@@ -1178,7 +1178,8 @@
   {
     error_code tmp_ec;
     file_status sym_status = symlink_status(p, tmp_ec);
- if (error(sym_status.type() == status_error, tmp_ec, p, ec, "boost::filesystem::remove"))
+ if (error(sym_status.type() == status_error, tmp_ec, p, ec,
+ "boost::filesystem::remove"))
       return false;
 
     return remove_file_or_directory(p, sym_status, ec);
@@ -1189,7 +1190,8 @@
   {
     error_code tmp_ec;
     file_status sym_status = symlink_status(p, tmp_ec);
- if (error(sym_status.type() == status_error, tmp_ec, p, ec, "boost::filesystem::remove_all"))
+ if (error(sym_status.type() == status_error, tmp_ec, p, ec,
+ "boost::filesystem::remove_all"))
       return 0;
 
     return exists(sym_status) // exists() throws nothing
@@ -1547,16 +1549,6 @@
     return ok;
   }
 
- //error_code dir_itr_close(void *& handle, void*& buffer)
- //{
- // std::free(buffer);
- // buffer = 0;
- // if (handle == 0)return ok;
- // DIR * h(static_cast<DIR*>(handle));
- // handle = 0;
- // return error_code(::closedir(h)== 0 ? 0 : errno, system_category);
- //}
-
   // warning: the only dirent member updated is d_name
   inline int readdir_r_simulator(DIR * dirp, struct dirent * entry,
     struct dirent ** result)// *result set to 0 on end of directory

Modified: sandbox/filesystem-v3/libs/filesystem/src/path.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/src/path.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/src/path.cpp 2010-01-06 14:23:33 EST (Wed, 06 Jan 2010)
@@ -71,6 +71,7 @@
   const wchar_t colon = L':';
   const wchar_t dot = L'.';
   const fs::path dot_path(L".");
+ const fs::path dot_dot_path(L"..");
 
 # else
 
@@ -82,6 +83,7 @@
   const char colon = ':';
   const char dot = '.';
   const fs::path dot_path(".");
+ const fs::path dot_dot_path("..");
 
 # endif
 
@@ -315,6 +317,7 @@
   path path::stem() const
   {
     path name(filename());
+ if (name == dot_path || name == dot_dot_path) return name;
     size_type pos(name.m_path.rfind(dot));
     return pos == string_type::npos
       ? name
@@ -324,6 +327,7 @@
   path path::extension() const
   {
     path name(filename());
+ if (name == dot_path || name == dot_dot_path) return path();
     size_type pos(name.m_path.rfind(dot));
     return pos == string_type::npos
       ? path()

Modified: sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/test/path_test.cpp 2010-01-06 14:23:33 EST (Wed, 06 Jan 2010)
@@ -669,6 +669,22 @@
   {
     std::cout << "query_and_decomposition_tests..." << std::endl;
 
+ // stem() tests not otherwise covered
+ BOOST_TEST(path("b").stem() == "b");
+ BOOST_TEST(path("a/b.txt").stem() == "b");
+ BOOST_TEST(path("a/b.").stem() == "b");
+ BOOST_TEST(path("a.b.c").stem() == "a.b");
+ BOOST_TEST(path("a.b.c.").stem() == "a.b.c");
+
+ // extension() tests not otherwise covered
+ BOOST_TEST(path("a/b").extension() == "");
+ BOOST_TEST(path("a/b.txt").extension() == ".txt");
+ BOOST_TEST(path("a/b.").extension() == ".");
+ BOOST_TEST(path("a.b.c").extension() == ".c");
+ BOOST_TEST(path("a.b.c.").extension() == ".");
+ BOOST_TEST(path("a/").extension() == "");
+
+ // main q & d test sequence
     path p;
     path q;
 
@@ -677,6 +693,8 @@
     BOOST_TEST(p.parent_path().string() == "");
     BOOST_TEST_EQ(q.remove_filename().string(), p.parent_path().string());
     BOOST_TEST(p.filename() == "");
+ BOOST_TEST(p.stem() == "");
+ BOOST_TEST(p.extension() == "");
     BOOST_TEST(p.root_name() == "");
     BOOST_TEST(p.root_directory() == "");
     BOOST_TEST(p.root_path().string() == "");
@@ -685,6 +703,8 @@
     BOOST_TEST(!p.has_root_directory());
     BOOST_TEST(!p.has_relative_path());
     BOOST_TEST(!p.has_filename());
+ BOOST_TEST(!p.has_stem());
+ BOOST_TEST(!p.has_extension());
     BOOST_TEST(!p.has_parent_path());
     BOOST_TEST(!p.is_absolute());
 
@@ -693,6 +713,8 @@
     BOOST_TEST(p.parent_path().string() == "");
     BOOST_TEST_EQ(q.remove_filename().string(), p.parent_path().string());
     BOOST_TEST(p.filename() == "/");
+ BOOST_TEST(p.stem() == "/");
+ BOOST_TEST(p.extension() == "");
     BOOST_TEST(p.root_name() == "");
     BOOST_TEST(p.root_directory() == "/");
     BOOST_TEST(p.root_path().string() == "/");
@@ -701,6 +723,8 @@
     BOOST_TEST(p.has_root_directory());
     BOOST_TEST(!p.has_relative_path());
     BOOST_TEST(p.has_filename());
+ BOOST_TEST(p.has_stem());
+ BOOST_TEST(!p.has_extension());
     BOOST_TEST(!p.has_parent_path());
     if (platform == "POSIX")
       BOOST_TEST(p.is_absolute());
@@ -712,6 +736,8 @@
     CHECK_EQUAL(p.parent_path().string(), "");
     BOOST_TEST_EQ(q.remove_filename().string(), p.parent_path().string());
     CHECK_EQUAL(p.filename(), "//");
+ CHECK_EQUAL(p.stem(), "//");
+ CHECK_EQUAL(p.extension(), "");
     CHECK_EQUAL(p.root_name(), "//");
     CHECK_EQUAL(p.root_directory(), "");
     CHECK_EQUAL(p.root_path().string(), "//");
@@ -720,15 +746,18 @@
     BOOST_TEST(!p.has_root_directory());
     BOOST_TEST(!p.has_relative_path());
     BOOST_TEST(p.has_filename());
+ BOOST_TEST(p.has_stem());
+ BOOST_TEST(!p.has_extension());
     BOOST_TEST(!p.has_parent_path());
     BOOST_TEST(!p.is_absolute());
 
-
     p = q = "///";
     CHECK_EQUAL(p.relative_path().string(), "");
     CHECK_EQUAL(p.parent_path().string(), "");
     BOOST_TEST_EQ(q.remove_filename().string(), p.parent_path().string());
     CHECK_EQUAL(p.filename(), "/");
+ CHECK_EQUAL(p.stem(), "/");
+ CHECK_EQUAL(p.extension(), "");
     CHECK_EQUAL(p.root_name(), "");
     CHECK_EQUAL(p.root_directory(), "/");
     CHECK_EQUAL(p.root_path().string(), "/");
@@ -737,6 +766,8 @@
     BOOST_TEST(p.has_root_directory());
     BOOST_TEST(!p.has_relative_path());
     BOOST_TEST(p.has_filename());
+ BOOST_TEST(p.has_stem());
+ BOOST_TEST(!p.has_extension());
     BOOST_TEST(!p.has_parent_path());
     if (platform == "POSIX")
       BOOST_TEST(p.is_absolute());
@@ -748,6 +779,8 @@
     BOOST_TEST(p.parent_path().string() == "");
     BOOST_TEST_EQ(q.remove_filename().string(), p.parent_path().string());
     BOOST_TEST(p.filename() == ".");
+ BOOST_TEST(p.stem() == ".");
+ BOOST_TEST(p.extension() == "");
     BOOST_TEST(p.root_name() == "");
     BOOST_TEST(p.root_directory() == "");
     BOOST_TEST(p.root_path().string() == "");
@@ -756,6 +789,8 @@
     BOOST_TEST(!p.has_root_directory());
     BOOST_TEST(p.has_relative_path());
     BOOST_TEST(p.has_filename());
+ BOOST_TEST(p.has_stem());
+ BOOST_TEST(!p.has_extension());
     BOOST_TEST(!p.has_parent_path());
     BOOST_TEST(!p.is_absolute());
 
@@ -764,6 +799,8 @@
     BOOST_TEST(p.parent_path().string() == "");
     BOOST_TEST_EQ(q.remove_filename().string(), p.parent_path().string());
     BOOST_TEST(p.filename() == "..");
+ BOOST_TEST(p.stem() == "..");
+ BOOST_TEST(p.extension() == "");
     BOOST_TEST(p.root_name() == "");
     BOOST_TEST(p.root_directory() == "");
     BOOST_TEST(p.root_path().string() == "");
@@ -772,6 +809,8 @@
     BOOST_TEST(!p.has_root_directory());
     BOOST_TEST(p.has_relative_path());
     BOOST_TEST(p.has_filename());
+ BOOST_TEST(p.has_stem());
+ BOOST_TEST(!p.has_extension());
     BOOST_TEST(!p.has_parent_path());
     BOOST_TEST(!p.is_absolute());
 
@@ -780,6 +819,8 @@
     BOOST_TEST(p.parent_path().string() == "");
     BOOST_TEST_EQ(q.remove_filename().string(), p.parent_path().string());
     BOOST_TEST(p.filename() == "foo");
+ BOOST_TEST(p.stem() == "foo");
+ BOOST_TEST(p.extension() == "");
     BOOST_TEST(p.root_name() == "");
     BOOST_TEST(p.root_directory() == "");
     BOOST_TEST(p.root_path().string() == "");
@@ -788,6 +829,8 @@
     BOOST_TEST(!p.has_root_directory());
     BOOST_TEST(p.has_relative_path());
     BOOST_TEST(p.has_filename());
+ BOOST_TEST(p.has_stem());
+ BOOST_TEST(!p.has_extension());
     BOOST_TEST(!p.has_parent_path());
     BOOST_TEST(!p.is_absolute());
 
@@ -796,6 +839,8 @@
     CHECK_EQUAL(p.parent_path().string(), "/");
     BOOST_TEST_EQ(q.remove_filename().string(), p.parent_path().string());
     CHECK_EQUAL(p.filename(), "foo");
+ CHECK_EQUAL(p.stem(), "foo");
+ CHECK_EQUAL(p.extension(), "");
     CHECK_EQUAL(p.root_name(), "");
     CHECK_EQUAL(p.root_directory(), "/");
     CHECK_EQUAL(p.root_path().string(), "/");
@@ -804,6 +849,8 @@
     BOOST_TEST(p.has_root_directory());
     BOOST_TEST(p.has_relative_path());
     BOOST_TEST(p.has_filename());
+ BOOST_TEST(p.has_stem());
+ BOOST_TEST(!p.has_extension());
     BOOST_TEST(p.has_parent_path());
     if (platform == "POSIX")
       BOOST_TEST(p.is_absolute());
@@ -815,6 +862,8 @@
     CHECK_EQUAL(p.parent_path().string(), "/foo");
     BOOST_TEST_EQ(q.remove_filename().string(), p.parent_path().string());
     CHECK_EQUAL(p.filename(), ".");
+ CHECK_EQUAL(p.stem(), ".");
+ CHECK_EQUAL(p.extension(), "");
     CHECK_EQUAL(p.root_name(), "");
     CHECK_EQUAL(p.root_directory(), "/");
     CHECK_EQUAL(p.root_path().string(), "/");
@@ -823,6 +872,8 @@
     BOOST_TEST(p.has_root_directory());
     BOOST_TEST(p.has_relative_path());
     BOOST_TEST(p.has_filename());
+ BOOST_TEST(p.has_stem());
+ BOOST_TEST(!p.has_extension());
     BOOST_TEST(p.has_parent_path());
     if (platform == "POSIX")
       BOOST_TEST(p.is_absolute());
@@ -853,6 +904,8 @@
     BOOST_TEST(p.parent_path().string() == "foo");
     BOOST_TEST_EQ(q.remove_filename().string(), p.parent_path().string());
     BOOST_TEST(p.filename() == "bar");
+ BOOST_TEST(p.stem() == "bar");
+ BOOST_TEST(p.extension() == "");
     BOOST_TEST(p.root_name() == "");
     BOOST_TEST(p.root_directory() == "");
     BOOST_TEST(p.root_path().string() == "");
@@ -861,6 +914,8 @@
     BOOST_TEST(!p.has_root_directory());
     BOOST_TEST(p.has_relative_path());
     BOOST_TEST(p.has_filename());
+ BOOST_TEST(p.has_stem());
+ BOOST_TEST(!p.has_extension());
     BOOST_TEST(p.has_parent_path());
     BOOST_TEST(!p.is_absolute());
 
@@ -1461,35 +1516,6 @@
     BOOST_TEST(!fs::portable_file_name(std::string("foo.")));
   }
   
- // stem_tests ---------------------------------------------------//
-
- void stem_tests()
- {
- std::cout << "stem_tests..." << std::endl;
-
- BOOST_TEST(path("b").stem() == "b");
- BOOST_TEST(path("a/b.txt").stem() == "b");
- BOOST_TEST(path("a/b.").stem() == "b");
- BOOST_TEST(path("a.b.c").stem() == "a.b");
- BOOST_TEST(path("a.b.c.").stem() == "a.b.c");
- BOOST_TEST(path("").stem() == "");
- }
-
- // extension_tests ---------------------------------------------------//
-
- void extension_tests()
- {
- std::cout << "extension_tests..." << std::endl;
-
- BOOST_TEST(path("a/b").extension() == "");
- BOOST_TEST(path("a/b.txt").extension() == ".txt");
- BOOST_TEST(path("a/b.").extension() == ".");
- BOOST_TEST(path("a.b.c").extension() == ".c");
- BOOST_TEST(path("a.b.c.").extension() == ".");
- BOOST_TEST(path("").extension() == "");
- BOOST_TEST(path("a/").extension() == ".");
- }
-
   // replace_extension_tests ---------------------------------------------------//
 
   void replace_extension_tests()
@@ -1551,8 +1577,6 @@
   non_member_tests();
   exception_tests();
   name_function_tests();
- stem_tests();
- extension_tests();
   replace_extension_tests();
 
   // verify deprecated names still available


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