Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76667 - in trunk: boost/filesystem/v3 libs/filesystem/v3/test libs/filesystem/v3/test/msvc10
From: bdawes_at_[hidden]
Date: 2012-01-24 14:43:12


Author: bemandawes
Date: 2012-01-24 14:43:11 EST (Tue, 24 Jan 2012)
New Revision: 76667
URL: http://svn.boost.org/trac/boost/changeset/76667

Log:
Fix #5653, recursive_directory_iterator(error_code) can still throw filesystem_error.
Fix a second bug, discovered while testing 5653; recursive_directory_iterator::increment with error_code argument was not reporting the end iterator.
Text files modified:
   trunk/boost/filesystem/v3/operations.hpp | 51 ++++++++++++++++++++++++++++-----------
   trunk/libs/filesystem/v3/test/msvc10/filesystem-v3.sln | 14 +++++-----
   trunk/libs/filesystem/v3/test/operations_test.cpp | 14 ++++++++++
   3 files changed, 57 insertions(+), 22 deletions(-)

Modified: trunk/boost/filesystem/v3/operations.hpp
==============================================================================
--- trunk/boost/filesystem/v3/operations.hpp (original)
+++ trunk/boost/filesystem/v3/operations.hpp 2012-01-24 14:43:11 EST (Tue, 24 Jan 2012)
@@ -765,24 +765,43 @@
     {
       if ((m_options & symlink_option::_detail_no_push) == symlink_option::_detail_no_push)
         m_options &= ~symlink_option::_detail_no_push;
- // patch for following else if contributed by Daniel Aarno, fixing #5652 for cyclic symlinks
- else if (((m_options & symlink_option::recurse) == symlink_option::recurse
- || !is_symlink(m_stack.top()->symlink_status()))
- && is_directory(m_stack.top()->status()))
+
+ else
       {
- if (ec == 0)
- m_stack.push(directory_iterator(m_stack.top()->path()));
- else
- {
- m_stack.push(directory_iterator(m_stack.top()->path(), *ec));
- if (*ec) return;
- }
- if (m_stack.top() != directory_iterator())
- {
- ++m_level;
+ // Logic for following predicate was contributed by Daniel Aarno to handle cyclic
+ // symlinks correctly and efficiently, fixing ticket #5652.
+ // if (((m_options & symlink_option::recurse) == symlink_option::recurse
+ // || !is_symlink(m_stack.top()->symlink_status()))
+ // && is_directory(m_stack.top()->status())) ...
+ // The predicate code has since been rewritten to pass error_code arguments,
+ // per ticket #5653.
+ bool or_pred = (m_options & symlink_option::recurse) == symlink_option::recurse
+ || (ec == 0 ? !is_symlink(m_stack.top()->symlink_status())
+ : !is_symlink(m_stack.top()->symlink_status(*ec)));
+ if (ec != 0 && *ec)
+ return;
+ bool and_pred = or_pred && (ec == 0 ? is_directory(m_stack.top()->status())
+ : is_directory(m_stack.top()->status(*ec)));
+ if (ec != 0 && *ec)
           return;
+
+ if (and_pred)
+ {
+ if (ec == 0)
+ m_stack.push(directory_iterator(m_stack.top()->path()));
+ else
+ {
+ m_stack.push(directory_iterator(m_stack.top()->path(), *ec));
+ if (*ec)
+ return;
+ }
+ if (m_stack.top() != directory_iterator())
+ {
+ ++m_level;
+ return;
+ }
+ m_stack.pop();
         }
- m_stack.pop();
       }
 
       while (!m_stack.empty() && ++m_stack.top() == directory_iterator())
@@ -859,6 +878,8 @@
       BOOST_ASSERT_MSG(m_imp.get(),
         "increment() on end recursive_directory_iterator");
       m_imp->increment(&ec);
+ if (m_imp->m_stack.empty())
+ m_imp.reset(); // done, so make end iterator
       return *this;
     }
 

Modified: trunk/libs/filesystem/v3/test/msvc10/filesystem-v3.sln
==============================================================================
--- trunk/libs/filesystem/v3/test/msvc10/filesystem-v3.sln (original)
+++ trunk/libs/filesystem/v3/test/msvc10/filesystem-v3.sln 2012-01-24 14:43:11 EST (Tue, 24 Jan 2012)
@@ -73,14 +73,14 @@
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "locale_info", "locale_info\locale_info.vcxproj", "{3667C35E-78D5-43D4-AAC2-349145E4341D}"
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ticket_5850", "ticket_5850\ticket_5850.vcxproj", "{B1FA4137-7B08-4113-9EC0-F3BAFEFBE2B7}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "thread_test", "thread_test\thread_test.vcxproj", "{20E2805D-9634-46CE-B979-21CCBBD16EA3}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "symlinked_cpp", "symlinked_cpp\symlinked_cpp.vcxproj", "{E37919AE-1A38-4E61-8E5E-FE4F981C6BFD}"
         ProjectSection(ProjectDependencies) = postProject
                 {F94CCADD-A90B-480C-A304-C19D015D36B1} = {F94CCADD-A90B-480C-A304-C19D015D36B1}
                 {FFD738F7-96F0-445C-81EA-551665EF53D1} = {FFD738F7-96F0-445C-81EA-551665EF53D1}
         EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "thread_test", "thread_test\thread_test.vcxproj", "{20E2805D-9634-46CE-B979-21CCBBD16EA3}"
-EndProject
 Global
         GlobalSection(SolutionConfigurationPlatforms) = preSolution
                 Debug|Win32 = Debug|Win32
@@ -175,14 +175,14 @@
                 {3667C35E-78D5-43D4-AAC2-349145E4341D}.Debug|Win32.Build.0 = Debug|Win32
                 {3667C35E-78D5-43D4-AAC2-349145E4341D}.Release|Win32.ActiveCfg = Release|Win32
                 {3667C35E-78D5-43D4-AAC2-349145E4341D}.Release|Win32.Build.0 = Release|Win32
- {B1FA4137-7B08-4113-9EC0-F3BAFEFBE2B7}.Debug|Win32.ActiveCfg = Debug|Win32
- {B1FA4137-7B08-4113-9EC0-F3BAFEFBE2B7}.Debug|Win32.Build.0 = Debug|Win32
- {B1FA4137-7B08-4113-9EC0-F3BAFEFBE2B7}.Release|Win32.ActiveCfg = Release|Win32
- {B1FA4137-7B08-4113-9EC0-F3BAFEFBE2B7}.Release|Win32.Build.0 = Release|Win32
                 {20E2805D-9634-46CE-B979-21CCBBD16EA3}.Debug|Win32.ActiveCfg = Debug|Win32
                 {20E2805D-9634-46CE-B979-21CCBBD16EA3}.Debug|Win32.Build.0 = Debug|Win32
                 {20E2805D-9634-46CE-B979-21CCBBD16EA3}.Release|Win32.ActiveCfg = Release|Win32
                 {20E2805D-9634-46CE-B979-21CCBBD16EA3}.Release|Win32.Build.0 = Release|Win32
+ {E37919AE-1A38-4E61-8E5E-FE4F981C6BFD}.Debug|Win32.ActiveCfg = Debug|Win32
+ {E37919AE-1A38-4E61-8E5E-FE4F981C6BFD}.Debug|Win32.Build.0 = Debug|Win32
+ {E37919AE-1A38-4E61-8E5E-FE4F981C6BFD}.Release|Win32.ActiveCfg = Release|Win32
+ {E37919AE-1A38-4E61-8E5E-FE4F981C6BFD}.Release|Win32.Build.0 = Release|Win32
         EndGlobalSection
         GlobalSection(SolutionProperties) = preSolution
                 HideSolutionNode = FALSE

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 2012-01-24 14:43:11 EST (Tue, 24 Jan 2012)
@@ -614,6 +614,20 @@
     BOOST_TEST(walk_tree(false) == 1);
     if (create_symlink_ok)
       BOOST_TEST(walk_tree(true) > 1);
+
+ // test iterator increment with error_code argument
+ boost::system::error_code ec;
+ int d1f1_count = 0;
+ for (fs::recursive_directory_iterator it (dir, fs::symlink_option::no_recurse);
+ it != fs::recursive_directory_iterator();
+ it.increment(ec))
+ {
+ if (it->path().filename() == "d1f1")
+ ++d1f1_count;
+ }
+ BOOST_TEST(!ec);
+ BOOST_TEST(d1f1_count == 1);
+
     cout << " recursive_directory_iterator_tests complete" << endl;
   }
 


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