Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50790 - in sandbox/filesystem-v3: boost/filesystem libs/filesystem/src libs/filesystem/test libs/filesystem/test/msvc
From: bdawes_at_[hidden]
Date: 2009-01-26 14:01:46


Author: bemandawes
Date: 2009-01-26 14:01:45 EST (Mon, 26 Jan 2009)
New Revision: 50790
URL: http://svn.boost.org/trac/boost/changeset/50790

Log:
Filesystem.v3: Windows copy_symlink now implemented. Tests passing on XP, Windows 7 beta 1, and Linux.
Text files modified:
   sandbox/filesystem-v3/boost/filesystem/operations.hpp | 29 ++++++++++++---------------
   sandbox/filesystem-v3/boost/filesystem/path.hpp | 10 ++++----
   sandbox/filesystem-v3/libs/filesystem/src/operations.cpp | 42 ++++++++++++++++++++++++++++++---------
   sandbox/filesystem-v3/libs/filesystem/test/msvc/common.vsprops | 2
   sandbox/filesystem-v3/libs/filesystem/test/operations_test.cpp | 16 +++++++++++++++
   5 files changed, 67 insertions(+), 32 deletions(-)

Modified: sandbox/filesystem-v3/boost/filesystem/operations.hpp
==============================================================================
--- sandbox/filesystem-v3/boost/filesystem/operations.hpp (original)
+++ sandbox/filesystem-v3/boost/filesystem/operations.hpp 2009-01-26 14:01:45 EST (Mon, 26 Jan 2009)
@@ -51,9 +51,6 @@
 
 #ifdef BOOST_WINDOWS_API
 # include <fstream>
-# if !defined(_WIN32_WINNT)
-# define _WIN32_WINNT 0x0500 // assume Windows 2000 or later SDK
-# endif
 #endif
 
 #include <boost/config/abi_prefix.hpp> // must be the last #include
@@ -460,7 +457,7 @@
 
     // constructors without path arguments
 
- filesystem_error::filesystem_error(
+ filesystem_error(
       const std::string & what_arg, system::error_code ec )
       : system::system_error(ec, what_arg)
     {
@@ -471,7 +468,7 @@
       catch (...) { m_imp_ptr.reset(); }
     }
 
- filesystem_error::filesystem_error(
+ filesystem_error(
       const char * what_arg, system::error_code ec )
       : system::system_error(ec, what_arg)
     {
@@ -482,7 +479,7 @@
       catch (...) { m_imp_ptr.reset(); }
     }
 
- filesystem_error::filesystem_error(
+ filesystem_error(
       const std::string & what_arg, int ev, const system::error_category & ecat )
       : system::system_error(ev, ecat, what_arg)
     {
@@ -493,7 +490,7 @@
       catch (...) { m_imp_ptr.reset(); }
     }
 
- filesystem_error::filesystem_error(
+ filesystem_error(
       const char * what_arg, int ev, const system::error_category & ecat )
       : system::system_error(ev, ecat, what_arg)
     {
@@ -506,7 +503,7 @@
 
     // constructors with one path argument
 
- filesystem_error::filesystem_error(
+ filesystem_error(
       const std::string & what_arg, const path & path1_arg,
       system::error_code ec )
       : system::system_error(ec, what_arg)
@@ -519,7 +516,7 @@
       catch (...) { m_imp_ptr.reset(); }
     }
 
- filesystem_error::filesystem_error(
+ filesystem_error(
       const char * what_arg, const path & path1_arg,
       system::error_code ec )
       : system::system_error(ec, what_arg)
@@ -532,7 +529,7 @@
       catch (...) { m_imp_ptr.reset(); }
     }
 
- filesystem_error::filesystem_error(
+ filesystem_error(
       const std::string & what_arg, const path & path1_arg,
       int ev, const system::error_category & ecat )
       : system::system_error(ev, ecat, what_arg)
@@ -545,7 +542,7 @@
       catch (...) { m_imp_ptr.reset(); }
     }
 
- filesystem_error::filesystem_error(
+ filesystem_error(
       const char * what_arg, const path & path1_arg,
       int ev, const system::error_category & ecat )
       : system::system_error(ev, ecat, what_arg)
@@ -560,7 +557,7 @@
 
     // constructors with two path arguments
     
- filesystem_error::filesystem_error(
+ filesystem_error(
       const std::string & what_arg, const path & path1_arg,
       const path & path2_arg, system::error_code ec )
       : system::system_error(ec, what_arg)
@@ -574,7 +571,7 @@
       catch (...) { m_imp_ptr.reset(); }
     }
 
- filesystem_error::filesystem_error(
+ filesystem_error(
       const char * what_arg, const path & path1_arg,
       const path & path2_arg, system::error_code ec )
       : system::system_error(ec, what_arg)
@@ -588,7 +585,7 @@
       catch (...) { m_imp_ptr.reset(); }
     }
 
- filesystem_error::filesystem_error(
+ filesystem_error(
       const std::string & what_arg, const path & path1_arg,
       const path & path2_arg, int ev, const system::error_category & ecat )
       : system::system_error(ev, ecat, what_arg)
@@ -602,7 +599,7 @@
       catch (...) { m_imp_ptr.reset(); }
     }
 
- filesystem_error::filesystem_error(
+ filesystem_error(
       const char * what_arg, const path & path1_arg,
       const path & path2_arg, int ev, const system::error_category & ecat )
       : system::system_error(ev, ecat, what_arg)
@@ -629,7 +626,7 @@
       return m_imp_ptr.get() ? m_imp_ptr->m_path2 : empty_path ;
     }
 
- const char * filesystem_error::what() const throw()
+ const char * what() const throw()
     {
       if ( !m_imp_ptr.get() )
         return system::system_error::what();

Modified: sandbox/filesystem-v3/boost/filesystem/path.hpp
==============================================================================
--- sandbox/filesystem-v3/boost/filesystem/path.hpp (original)
+++ sandbox/filesystem-v3/boost/filesystem/path.hpp 2009-01-26 14:01:45 EST (Mon, 26 Jan 2009)
@@ -759,11 +759,11 @@
   inline bool operator==( const path::string_type & lhs, const path & rhs ) { return rhs == lhs; }
   inline bool operator==( const path::value_type * lhs, const path & rhs ) { return rhs == lhs; }
 # else // BOOST_POSIX_API
- inline bool operator==( const path & lhs, const path & rhs ) { return lhs.source_string() == rhs.source_string(); }
- inline bool operator==( const path & lhs, const path::string_type & rhs ) { return lhs.source_string() == rhs; }
- inline bool operator==( const path & lhs, const path::value_type * rhs ) { return lhs.source_string() == rhs; }
- inline bool operator==( const path::string_type & lhs, const path & rhs ) { return lhs == rhs.source_string(); }
- inline bool operator==( const path::value_type * lhs, const path & rhs ) { return lhs == rhs.source_string(); }
+ inline bool operator==( const path & lhs, const path & rhs ) { return lhs.source() == rhs.source(); }
+ inline bool operator==( const path & lhs, const path::string_type & rhs ) { return lhs.source() == rhs; }
+ inline bool operator==( const path & lhs, const path::value_type * rhs ) { return lhs.source() == rhs; }
+ inline bool operator==( const path::string_type & lhs, const path & rhs ) { return lhs == rhs.source(); }
+ inline bool operator==( const path::value_type * lhs, const path & rhs ) { return lhs == rhs.source(); }
 # endif
 
 

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 2009-01-26 14:01:45 EST (Mon, 26 Jan 2009)
@@ -36,11 +36,6 @@
       // That is required at least on Solaris, and possibly on other
       // systems as well.
 
-// If not already defined, _WIN32_WINNT used to be defined as 0x0500
-// (Windows 2K or later) at this point. But with Vista it becomes more
-// important to know the exact version present, so sdkddkver.h is
-// now required; it will supply specific version infomation.
-
 #include <boost/filesystem/operations.hpp>
 #include <boost/scoped_array.hpp>
 #include <boost/throw_exception.hpp>
@@ -65,7 +60,11 @@
 # endif
 
 # if defined(BOOST_WINDOWS_API)
+
 # include <windows.h>
+# if !defined(_WIN32_WINNT)
+# define _WIN32_WINNT 0x0500
+# endif
 # if defined(__BORLANDC__) || defined(__MWERKS__)
 # if defined(__BORLANDC__)
         using std::time_t;
@@ -591,9 +590,32 @@
   BOOST_FILESYSTEM_DECL
   void copy_symlink( const path & from, const path & to, system::error_code & ec )
   {
+# if defined(BOOST_WINDOWS_API) && _WIN32_WINNT < 0x0600 // SDK earlier than Vista and Server 2008
+ error( true, error_code(BOOST_ERROR_NOT_SUPPORTED, system_category), to, from, ec,
+ "boost::filesystem::copy_symlink" );
+
+# elif defined(BOOST_WINDOWS_API)
+
+ // see if actually supported by Windows runtime dll
+ if ( error( !create_symbolic_link_api,
+ error_code(BOOST_ERROR_NOT_SUPPORTED, system_category),
+ to, from, ec,
+ "boost::filesystem::copy_symlink" ) )
+ return;
+
+ // preconditions met, so attempt the copy
+ error( !::CopyFileEx( from.c_str(), to.c_str(), 0, 0, 0,
+ COPY_FILE_COPY_SYMLINK | COPY_FILE_FAIL_IF_EXISTS ), to, from, ec,
+ "boost::filesystem::copy_symlink" );
+
+# else // BOOST_POSIX_API
+
     path p( read_symlink( from, ec ) );
     if ( &ec != &throws() && ec ) return;
     create_symlink( p, to, ec );
+
+# endif
+
   }
 
   BOOST_FILESYSTEM_DECL
@@ -694,7 +716,7 @@
   void create_symlink( const path & to, const path & from, error_code & ec )
   {
 # if defined(BOOST_WINDOWS_API) && _WIN32_WINNT < 0x0600 // SDK earlier than Vista and Server 2008
-
+ std::cout << "*********************************" << _WIN32_WINNT << std::endl;
     error( true, error_code(BOOST_ERROR_NOT_SUPPORTED, system_category), to, from, ec,
       "boost::filesystem::create_directory_symlink" );
 # else
@@ -1047,7 +1069,7 @@
       {
         if( result != static_cast<ssize_t>(path_max))
         {
- symlink_path = buf.get();
+ symlink_path.assign( buf.get(), buf.get() + result );
           if ( &ec != &throws() ) ec.clear();
           break;
         }
@@ -1488,10 +1510,10 @@
   }
 
   error_code dir_itr_first( void *& handle, void *& buffer,
- const string & dir, string & target,
+ const char * dir, string & target,
     fs::file_status &, fs::file_status & )
   {
- if ( (handle = ::opendir( dir.c_str() )) == 0 )
+ if ( (handle = ::opendir( dir )) == 0 )
       return error_code( errno, system_category );
     target = string( "." ); // string was static but caused trouble
                                  // when iteration called from dtor, after
@@ -1633,7 +1655,7 @@
   #if defined(BOOST_POSIX_API)
       it.m_imp->buffer,
   #endif
- p, filename, file_stat, symlink_file_stat );
+ p.c_str(), filename, file_stat, symlink_file_stat );
 
     if ( result )
     {

Modified: sandbox/filesystem-v3/libs/filesystem/test/msvc/common.vsprops
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/test/msvc/common.vsprops (original)
+++ sandbox/filesystem-v3/libs/filesystem/test/msvc/common.vsprops 2009-01-26 14:01:45 EST (Mon, 26 Jan 2009)
@@ -14,6 +14,6 @@
         />
         <Tool
                 Name="VCLinkerTool"
- AdditionalLibraryDirectories="$(BOOST_TRUNK)/lib"
+ AdditionalLibraryDirectories=""
         />
 </VisualStudioPropertySheet>

Modified: sandbox/filesystem-v3/libs/filesystem/test/operations_test.cpp
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/test/operations_test.cpp (original)
+++ sandbox/filesystem-v3/libs/filesystem/test/operations_test.cpp 2009-01-26 14:01:45 EST (Mon, 26 Jan 2009)
@@ -478,6 +478,12 @@
       BOOST_CHECK( fs::exists( file_ph ) );
       BOOST_CHECK( fs::equivalent( from_ph, file_ph ) );
 
+ if ( platform == "POSIX" )
+ {
+ //std::cout << fs::read_symlink( from_ph ).string() << ", " << file_ph.string() << "\n";
+ BOOST_CHECK( fs::read_symlink( from_ph ) == file_ph );
+ }
+
       fs::file_status stat = fs::symlink_status( from_ph );
       BOOST_CHECK( fs::exists( stat ) );
       BOOST_CHECK( !fs::is_directory( stat ) );
@@ -491,6 +497,16 @@
       BOOST_CHECK( fs::is_regular_file( stat ) );
       BOOST_CHECK( !fs::is_other( stat ) );
       BOOST_CHECK( !fs::is_symlink( stat ) );
+
+ // since create_symlink worked, copy_symlink should also work
+ fs::path symlink2_ph( dir / "symlink2" );
+ fs::copy_symlink( from_ph, symlink2_ph );
+ stat = fs::symlink_status( symlink2_ph );
+ BOOST_CHECK( fs::is_symlink( stat ) );
+ BOOST_CHECK( fs::exists( stat ) );
+ BOOST_CHECK( !fs::is_directory( stat ) );
+ BOOST_CHECK( !fs::is_regular_file( stat ) );
+ BOOST_CHECK( !fs::is_other( stat ) );
     }
 
     error_code ec = error_code();


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