|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r50754 - in sandbox/filesystem-v3: boost/filesystem libs/filesystem/doc libs/filesystem/src libs/filesystem/test
From: bdawes_at_[hidden]
Date: 2009-01-24 11:00:33
Author: bemandawes
Date: 2009-01-24 11:00:32 EST (Sat, 24 Jan 2009)
New Revision: 50754
URL: http://svn.boost.org/trac/boost/changeset/50754
Log:
filesystem.v3: work-in-progress: add new functions from Walter Landry
Text files modified:
sandbox/filesystem-v3/boost/filesystem/operations.hpp | 22 ++++++
sandbox/filesystem-v3/libs/filesystem/doc/v3_design.html | 14 ++++
sandbox/filesystem-v3/libs/filesystem/src/operations.cpp | 118 ++++++++++++++++++++++++++++++++++++++++
sandbox/filesystem-v3/libs/filesystem/test/operations_test.cpp | 4 +
4 files changed, 154 insertions(+), 4 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-24 11:00:32 EST (Sat, 24 Jan 2009)
@@ -105,7 +105,7 @@
private:
// the internal representation is unspecified so that additional state
// information such as permissions can be added in the future; this
- // implementation just uses status_type as the internal representation
+ // implementation just uses file_type as the internal representation
file_type m_value;
};
@@ -131,7 +131,7 @@
//--------------------------------------------------------------------------------------//
// //
-// query functions //
+// status query functions //
// //
//--------------------------------------------------------------------------------------//
@@ -189,10 +189,22 @@
path complete( const path & p, const path & base = initial_path() );
BOOST_FILESYSTEM_DECL
+ void copy_any( const path & from, const path & to,
+ system::error_code & ec = throws() );
+
+ BOOST_FILESYSTEM_DECL
+ void copy_directory( const path & from, const path & to,
+ system::error_code & ec = throws() );
+
+ BOOST_FILESYSTEM_DECL
void copy_file( const path & from, const path & to,
system::error_code & ec = throws() );
BOOST_FILESYSTEM_DECL
+ void copy_symlink( const path & from, const path & to,
+ system::error_code & ec = throws() );
+
+ BOOST_FILESYSTEM_DECL
bool create_directories( const path & p/*,
system::error_code & ec = throws()*/ );
@@ -225,6 +237,9 @@
boost::uintmax_t file_size( const path & p,
system::error_code & ec = throws() );
+ BOOST_FILESYSTEM_DECL
+ boost::uintmax_t hard_link_count( const path & p, system::error_code & ec = throws() );
+
// initial_path() declaration precedes complete()
BOOST_FILESYSTEM_DECL
@@ -236,6 +251,9 @@
system::error_code & ec = throws() );
BOOST_FILESYSTEM_DECL
+ path read_symlink( const path & p, system::error_code & ec = throws() );
+
+ BOOST_FILESYSTEM_DECL
bool remove( const path & p, system::error_code & ec = throws() );
BOOST_FILESYSTEM_DECL
Modified: sandbox/filesystem-v3/libs/filesystem/doc/v3_design.html
==============================================================================
--- sandbox/filesystem-v3/libs/filesystem/doc/v3_design.html (original)
+++ sandbox/filesystem-v3/libs/filesystem/doc/v3_design.html 2009-01-24 11:00:32 EST (Sat, 24 Jan 2009)
@@ -42,7 +42,8 @@
<a href="#Solution">Solution</a><br>
<a href="#Details">Details</a><br>
<a href="#Other-changes">Other changes</a><br>
- Prototype</td>
+ Prototype<br>
+ Acknowledgements</td>
</tr>
<tr>
<td width="100%" bgcolor="#D7EEFF" align="center">
@@ -172,9 +173,13 @@
<p><b>Additional filesystem operations:</b></p>
<ul>
+ <li>copy_any() added.</li>
+ <li>copy_directory() added.</li>
+ <li>copy_symlink() added.</li>
<li>create_symlink() now available on Windows if supported (i.e. Vista and
later).</li>
<li>create_directory_symlink() added.</li>
+ <li>read_symlink() added.</li>
</ul>
<h2><a name="Prototype">Prototype</a></h2>
@@ -182,9 +187,14 @@
<p>Currently incomplete. Not thoroughly tested. Should not be used for
production work.</p>
+<h2><a name="Acknowledgements">Acknowledgements</a></h2>
+
+<p>Walter Landry contributed both the design and implementation of the copy_any,
+copy_directory, copy_symlink, and read_symlink functions.</p>
+
<hr>
<p>Revised
-<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->21 January, 2009<!--webbot bot="Timestamp" endspan i-checksum="39336" --></p>
+<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->24 January, 2009<!--webbot bot="Timestamp" endspan i-checksum="39342" --></p>
<p>© Copyright Beman Dawes, 2008</p>
<p> Use, modification, and distribution are subject to the Boost Software
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-24 11:00:32 EST (Sat, 24 Jan 2009)
@@ -136,6 +136,8 @@
# define BOOST_CREATE_SYMBOLIC_LINK(F,T,Flag) (::symlink( T, F ) == 0)
# define BOOST_REMOVE_DIRECTORY(P) (::rmdir( P ) == 0)
# define BOOST_DELETE_FILE(P) (::unlink( P ) == 0)
+# define BOOST_COPY_DIRECTORY(F,T) (!(::stat( from.c_str(), &from_stat ) != 0\
+ || ::mkdir( to.c_str(),from_stat.st_mode ) != 0))
# define BOOST_COPY_FILE(F,T) copy_file_api(F, T)
# define BOOST_MOVE_FILE(F,T) (::rename(F, T) == 0)
@@ -151,8 +153,10 @@
# define BOOST_CREATE_SYMBOLIC_LINK(F,T,Flag) (create_symbolic_link_api( F, T, Flag ) != 0)
# define BOOST_REMOVE_DIRECTORY(P) (::RemoveDirectoryW(P) != 0)
# define BOOST_DELETE_FILE(P) (::DeleteFileW(P) != 0)
+# define BOOST_COPY_DIRECTORY(F,T) (::CreateDirectoryExW( F, T, 0 ) != 0)
# define BOOST_COPY_FILE(F,T) (::CopyFileW( F, T, /*fail_if_exists=*/true ) != 0)
# define BOOST_MOVE_FILE(F,T) (::MoveFileW( F, T ) != 0)
+# define BOOST_READ_SYMLINK(P,T)
# define BOOST_ERROR_ALREADY_EXISTS ERROR_ALREADY_EXISTS
# define BOOST_ERROR_NOT_SUPPORTED ERROR_NOT_SUPPORTED
@@ -541,6 +545,43 @@
}
BOOST_FILESYSTEM_DECL
+ void copy_any( const path & from, const path & to, system::error_code & ec )
+ {
+ file_status s( symlink_status( from, ec ) );
+ if ( &ec != &throws() && ec ) return;
+
+ if( is_symlink( s ) )
+ {
+ copy_symlink( from, to, ec );
+ }
+ else if( is_directory( s ) )
+ {
+ copy_directory( from, to, ec );
+ }
+ else if( is_regular_file( s ) )
+ {
+ copy_file( from, to, ec );
+ }
+ else
+ {
+ if ( &ec == &throws() )
+ throw_exception( filesystem_error( "boost::filesystem::copy",
+ from, to, BOOST_ERROR_NOT_SUPPORTED, system_category ) );
+ ec.assign( BOOST_ERROR_NOT_SUPPORTED, system_category );
+ }
+ }
+
+ BOOST_FILESYSTEM_DECL
+ void copy_directory( const path & from, const path & to, system::error_code & ec)
+ {
+# ifdef BOOST_POSIX_API
+ struct stat from_stat;
+# endif
+ error( !BOOST_COPY_DIRECTORY( from.c_str(), to.c_str() ),
+ from, to, ec, "boost::filesystem::copy_directory" );
+ }
+
+ BOOST_FILESYSTEM_DECL
void copy_file( const path & from, const path & to, error_code & ec )
{
error( !BOOST_COPY_FILE( from.c_str(), to.c_str() ),
@@ -548,6 +589,14 @@
}
BOOST_FILESYSTEM_DECL
+ void copy_symlink( const path & from, const path & to, system::error_code & ec )
+ {
+ path p( read_symlink( from, ec ) );
+ if ( &ec != &throws() && ec ) return;
+ create_symlink( p, to, ec );
+ }
+
+ BOOST_FILESYSTEM_DECL
bool create_directories( const path & p/*, system::error_code & ec*/ )
{
if ( p.empty() || exists(p))
@@ -838,6 +887,34 @@
}
BOOST_FILESYSTEM_DECL
+ boost::uintmax_t hard_link_count( const path & p, system::error_code & ec )
+ {
+# ifdef BOOST_WINDOWS_API
+
+ // Link count info is only available through GetFileInformationByHandle
+ BY_HANDLE_FILE_INFORMATION info;
+ handle_wrapper h(
+ create_file_handle( p.c_str(), 0,
+ FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
+ OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 ) );
+ return
+ !error( h.handle == INVALID_HANDLE_VALUE,
+ p, ec, "boost::filesystem::hard_link_count" )
+ && !error( ::GetFileInformationByHandle( h.handle, &info ) == 0,
+ p, ec, "boost::filesystem::hard_link_count" )
+ ? info.nNumberOfLinks
+ : 0;
+# else
+
+ struct stat path_stat;
+ return error( ::stat( p.c_str(), &path_stat ) != 0,
+ p, ec, "boost::filesystem::hard_link_count" )
+ ? 0
+ : static_cast<boost::uintmax_t>( path_stat.st_nlink );
+# endif
+ }
+
+ BOOST_FILESYSTEM_DECL
path initial_path( error_code & ec )
{
static path init_path;
@@ -939,6 +1016,47 @@
p, ec, "boost::filesystem::last_write_time" );
# endif
}
+
+ BOOST_FILESYSTEM_DECL
+ path read_symlink( const path & p, system::error_code & ec )
+ {
+# ifdef BOOST_WINDOWS_API
+
+ if ( &ec == &throws() )
+ throw_exception( filesystem_error( "boost::filesystem::read_symlink",
+ p, BOOST_ERROR_NOT_SUPPORTED, system_category ) );
+ else ec.assign( BOOST_ERROR_NOT_SUPPORTED, system_category );
+ return path();
+
+# else
+
+ path symlink_path;
+ for ( std::size_t path_max = 64;; path_max *= 2 ) // loop 'til buffer large enough
+ {
+ boost::scoped_array<char> buf( new char[path_max] );
+ ssize_t result;
+ if ( (result=::readlink( p.c_str(), buf.get(), path_max) ) == -1 )
+ {
+ if ( &ec == &throws() )
+ throw_exception( filesystem_error( "boost::filesystem::read_symlink",
+ p, errno, system_category ) );
+ else ec.assign( errno, system_category );
+ break;
+ }
+ else
+ {
+ if( result != static_cast<ssize_t>(path_max))
+ {
+ symlink_path = buf.get();
+ if ( &ec != &throws() ) ec.clear();
+ break;
+ }
+ }
+ }
+ return symlink_path;
+
+# endif
+ }
BOOST_FILESYSTEM_DECL
bool remove( const path & p, error_code & ec )
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-24 11:00:32 EST (Sat, 24 Jan 2009)
@@ -432,6 +432,8 @@
BOOST_CHECK( fs::exists( from_ph ) );
BOOST_CHECK( fs::exists( file_ph ) );
BOOST_CHECK( fs::equivalent( from_ph, file_ph ) );
+ BOOST_CHECK( fs::hard_link_count( from_ph ) == 2 );
+ BOOST_CHECK( fs::hard_link_count( file_ph ) == 2 );
}
// Although tests may be running on a FAT or other file system that does
@@ -884,6 +886,8 @@
BOOST_CHECK( fs::is_regular_file( file_ph ) );
BOOST_CHECK( BOOST_FS_IS_EMPTY( file_ph ) );
BOOST_CHECK( fs::file_size( file_ph ) == 0 );
+ BOOST_CHECK( fs::hard_link_count( file_ph ) == 1 );
+
bad_create_directory_path = file_ph;
BOOST_CHECK( CHECK_EXCEPTION( bad_create_directory, EEXIST ) );
fs::file_status stat = fs::status( file_ph );
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