📄 operations.hpp
字号:
}
BOOST_FS_FUNC(space_info) space( const Path & ph )
{
detail::space_pair result
= detail::space_api( ph.external_file_string() );
if ( result.first != 0 )
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::space", ph, result.first ) );
return result.second;
}
BOOST_FS_FUNC(std::time_t) last_write_time( const Path & ph )
{
detail::time_pair result
= detail::last_write_time_api( ph.external_file_string() );
if ( result.first != 0 )
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::last_write_time", ph, result.first ) );
return result.second;
}
// operations --------------------------------------------------------------//
BOOST_FS_FUNC(bool) create_directory( const Path & dir_ph )
{
detail::query_pair result(
detail::create_directory_api( dir_ph.external_directory_string() ) );
if ( result.first != 0 )
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::create_directory",
dir_ph, result.first ) );
return result.second;
}
#if !defined(BOOST_WINDOWS_API) || defined(BOOST_FS_HARD_LINK)
BOOST_FS_FUNC(void)
create_hard_link( const Path & to_ph, const Path & from_ph )
{
system_error_type result(
detail::create_hard_link_api(
to_ph.external_file_string(),
from_ph.external_file_string() ) );
if ( result != 0 )
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::create_hard_link",
to_ph, from_ph, result ) );
}
BOOST_FS_FUNC(system_error_type)
create_hard_link( const Path & to_ph, const Path & from_ph,
system_error_type & ec )
{
ec = detail::create_hard_link_api(
to_ph.external_file_string(),
from_ph.external_file_string() );
return ec;
}
#endif
BOOST_FS_FUNC(void)
create_symlink( const Path & to_ph, const Path & from_ph )
{
system_error_type result(
detail::create_symlink_api(
to_ph.external_file_string(),
from_ph.external_file_string() ) );
if ( result )
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::create_symlink",
to_ph, from_ph, result ) );
}
BOOST_FS_FUNC(system_error_type)
create_symlink( const Path & to_ph, const Path & from_ph,
system_error_type & ec )
{
ec = detail::create_symlink_api(
to_ph.external_file_string(),
from_ph.external_file_string() );
return ec;
}
BOOST_FS_FUNC(bool) remove( const Path & ph )
{
if ( exists( ph )
|| is_symlink( ph ) ) // handle dangling symbolic links
// note that the POSIX behavior for symbolic links is what we want;
// the link rather than what it points to is deleted. Windows behavior
// doesn't matter; is_symlink() is always false on Windows.
{
system_error_type result = detail::remove_api( ph.external_file_string() );
if ( result != 0 )
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::remove",
ph, result ) );
return true;
}
return false;
}
BOOST_FS_FUNC(unsigned long) remove_all( const Path & ph )
{
return exists( ph )|| is_symlink( ph )
? detail::remove_all_aux( ph ) : 0;
}
BOOST_FS_FUNC(void) rename( const Path & from_path, const Path & to_path )
{
system_error_type result = detail::rename_api(
from_path.external_directory_string(),
to_path.external_directory_string() );
if ( result != 0 )
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::rename",
from_path, to_path, result ) );
}
BOOST_FS_FUNC(void) copy_file( const Path & from_path, const Path & to_path )
{
system_error_type result = detail::copy_file_api(
from_path.external_directory_string(),
to_path.external_directory_string() );
if ( result != 0 )
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::copy_file",
from_path, to_path, result ) );
}
template< class Path >
Path current_path()
{
typename Path::external_string_type ph;
boost::filesystem::system_error_type result;
if ( (result = detail::get_current_path_api( ph )) != 0 )
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::current_path", result ) );
return Path( Path::traits_type::to_internal( ph ) );
}
template< class Path >
const Path & initial_path()
{
static Path init_path;
if ( init_path.empty() ) init_path = current_path<Path>();
return init_path;
}
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
// legacy support
inline path current_path() // overload supports pre-i18n apps
{ return current_path<boost::filesystem::path>(); }
inline const path & initial_path() // overload supports pre-i18n apps
{ return initial_path<boost::filesystem::path>(); }
# endif
BOOST_FS_FUNC(Path) system_complete( const Path & ph )
{
# ifdef BOOST_WINDOWS_API
if ( ph.empty() ) return ph;
BOOST_FS_TYPENAME Path::external_string_type sys_ph;
boost::filesystem::system_error_type result;
if ( (result = detail::get_full_path_name_api( ph.external_file_string(),
sys_ph )) != 0 )
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::system_complete", ph, result ) );
return Path( Path::traits_type::to_internal( sys_ph ) );
# else
return (ph.empty() || ph.is_complete())
? ph : current_path<Path>() / ph;
# endif
}
BOOST_FS_FUNC(Path)
complete( const Path & ph,
const Path & base/* = initial_path<Path>() */)
{
BOOST_ASSERT( base.is_complete()
&& (ph.is_complete() || !ph.has_root_name())
&& "boost::filesystem::complete() precondition not met" );
# ifdef BOOST_WINDOWS_PATH
if (ph.empty() || ph.is_complete()) return ph;
if ( !ph.has_root_name() )
return ph.has_root_directory()
? Path( base.root_name() ) / ph
: base / ph;
return base / ph;
# else
return (ph.empty() || ph.is_complete()) ? ph : base / ph;
# endif
}
// VC++ 7.1 had trouble with default arguments, so separate one argument
// signatures are provided as workarounds; the effect is the same.
BOOST_FS_FUNC(Path) complete( const Path & ph )
{ return complete( ph, initial_path<Path>() ); }
BOOST_FS_FUNC(void)
last_write_time( const Path & ph, const std::time_t new_time )
{
boost::filesystem::system_error_type result;
if ( (result = detail::last_write_time_api( ph.external_file_string(),
new_time )) != 0 )
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::last_write_time", ph, result ) );
}
# ifndef BOOST_FILESYSTEM_NARROW_ONLY
// "do-the-right-thing" overloads ---------------------------------------//
inline file_status status( const path & ph )
{ return status<path>( ph ); }
inline file_status status( const wpath & ph )
{ return status<wpath>( ph ); }
inline file_status status( const path & ph, system_error_type & ec )
{ return status<path>( ph, ec ); }
inline file_status status( const wpath & ph, system_error_type & ec )
{ return status<wpath>( ph, ec ); }
inline file_status symlink_status( const path & ph )
{ return symlink_status<path>( ph ); }
inline file_status symlink_status( const wpath & ph )
{ return symlink_status<wpath>( ph ); }
inline file_status symlink_status( const path & ph, system_error_type & ec )
{ return symlink_status<path>( ph, ec ); }
inline file_status symlink_status( const wpath & ph, system_error_type & ec )
{ return symlink_status<wpath>( ph, ec ); }
inline bool exists( const path & ph ) { return exists<path>( ph ); }
inline bool exists( const wpath & ph ) { return exists<wpath>( ph ); }
inline bool is_directory( const path & ph )
{ return is_directory<path>( ph ); }
inline bool is_directory( const wpath & ph )
{ return is_directory<wpath>( ph ); }
inline bool is_regular( const path & ph )
{ return is_regular<path>( ph ); }
inline bool is_regular( const wpath & ph )
{ return is_regular<wpath>( ph ); }
inline bool is_other( const path & ph )
{ return is_other<path>( ph ); }
inline bool is_other( const wpath & ph )
{ return is_other<wpath>( ph ); }
inline bool is_symlink( const path & ph )
{ return is_symlink<path>( ph ); }
inline bool is_symlink( const wpath & ph )
{ return is_symlink<wpath>( ph ); }
inline bool is_empty( const path & ph )
{ return is_empty<path>( ph ); }
inline bool is_empty( const wpath & ph )
{ return is_empty<wpath>( ph ); }
inline bool equivalent( const path & ph1, const path & ph2 )
{ return equivalent<path>( ph1, ph2 ); }
inline bool equivalent( const wpath & ph1, const wpath & ph2 )
{ return equivalent<wpath>( ph1, ph2 ); }
inline boost::uintmax_t file_size( const path & ph )
{ return file_size<path>( ph ); }
inline boost::uintmax_t file_size( const wpath & ph )
{ return file_size<wpath>( ph ); }
inline space_info space( const path & ph )
{ return space<path>( ph ); }
inline space_info space( const wpath & ph )
{ return space<wpath>( ph ); }
inline std::time_t last_write_time( const path & ph )
{ return last_write_time<path>( ph ); }
inline std::time_t last_write_time( const wpath & ph )
{ return last_write_time<wpath>( ph ); }
inline bool create_directory( const path & dir_ph )
{ return create_directory<path>( dir_ph ); }
inline bool create_directory( const wpath & dir_ph )
{ return create_directory<wpath>( dir_ph ); }
#if !defined(BOOST_WINDOWS_API) || defined(BOOST_FS_HARD_LINK)
inline void create_hard_link( const path & to_ph,
const path & from_ph )
{ return create_hard_link<path>( to_ph, from_ph ); }
inline void create_hard_link( const wpath & to_ph,
const wpath & from_ph )
{ return create_hard_link<wpath>( to_ph, from_ph ); }
inline system_error_type create_hard_link( const path & to_ph,
const path & from_ph, system_error_type & ec )
{ return create_hard_link<path>( to_ph, from_ph, ec ); }
inline system_error_type create_hard_link( const wpath & to_ph,
const wpath & from_ph, system_error_type & ec )
{ return create_hard_link<wpath>( to_ph, from_ph, ec ); }
#endif
inline void create_symlink( const path & to_ph,
const path & from_ph )
{ return create_symlink<path>( to_ph, from_ph ); }
inline void create_symlink( const wpath & to_ph,
const wpath & from_ph )
{ return create_symlink<wpath>( to_ph, from_ph ); }
inline system_error_type create_symlink( const path & to_ph,
const path & from_ph, system_error_type & ec )
{ return create_symlink<path>( to_ph, from_ph, ec ); }
inline system_error_type create_symlink( const wpath & to_ph,
const wpath & from_ph, system_error_type & ec )
{ return create_symlink<wpath>( to_ph, from_ph, ec ); }
inline bool remove( const path & ph )
{ return remove<path>( ph ); }
inline bool remove( const wpath & ph )
{ return remove<wpath>( ph ); }
inline unsigned long remove_all( const path & ph )
{ return remove_all<path>( ph ); }
inline unsigned long remove_all( const wpath & ph )
{ return remove_all<wpath>( ph ); }
inline void rename( const path & from_path, const path & to_path )
{ return rename<path>( from_path, to_path ); }
inline void rename( const wpath & from_path, const wpath & to_path )
{ return rename<wpath>( from_path, to_path ); }
inline void copy_file( const path & from_path, const path & to_path )
{ return copy_file<path>( from_path, to_path ); }
inline void copy_file( const wpath & from_path, const wpath & to_path )
{ return copy_file<wpath>( from_path, to_path ); }
inline path system_complete( const path & ph )
{ return system_complete<path>( ph ); }
inline wpath system_complete( const wpath & ph )
{ return system_complete<wpath>( ph ); }
inline path complete( const path & ph,
const path & base/* = initial_path<path>()*/ )
{ return complete<path>( ph, base ); }
inline wpath complete( const wpath & ph,
const wpath & base/* = initial_path<wpath>()*/ )
{ return complete<wpath>( ph, base ); }
inline path complete( const path & ph )
{ return complete<path>( ph, initial_path<path>() ); }
inline wpath complete( const wpath & ph )
{ return complete<wpath>( ph, initial_path<wpath>() ); }
inline void last_write_time( const path & ph, const std::time_t new_time )
{ last_write_time<path>( ph, new_time ); }
inline void last_write_time( const wpath & ph, const std::time_t new_time )
{ last_write_time<wpath>( ph, new_time ); }
# endif // BOOST_FILESYSTEM_NARROW_ONLY
namespace detail
{
template<class Path>
unsigned long remove_all_aux( const Path & ph )
{
static const boost::filesystem::basic_directory_iterator<Path> end_itr;
unsigned long count = 1;
if ( !boost::filesystem::is_symlink( ph ) // don't recurse symbolic links
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -