[Boost-bugs] [Boost C++ Libraries] #2866: boost::filesystem::rename throw exception when target file exists, but documentation tell us that it must be replaced

Subject: [Boost-bugs] [Boost C++ Libraries] #2866: boost::filesystem::rename throw exception when target file exists, but documentation tell us that it must be replaced
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-03-18 15:44:17


#2866: boost::filesystem::rename throw exception when target file exists, but
documentation tell us that it must be replaced
--------------------------------+-------------------------------------------
 Reporter: t.kozlov_at_[hidden] | Owner: bemandawes
     Type: Bugs | Status: new
Milestone: Boost 1.39.0 | Component: filesystem
  Version: Boost 1.38.0 | Severity: Cosmetic
 Keywords: |
--------------------------------+-------------------------------------------
 [Note: If from_p and to_p resolve to the same file, no action is taken.
 '''Otherwise, if to_p resolves to an existing file, it is removed'''. A
 symbolic link is itself renamed, rather than the file it resolves to being
 renamed. -- end note]

 A part from libs/filesystem/operations.cpp

 {{{
 BOOST_FILESYSTEM_DECL error_code
 rename_api( const std::string & from, const std::string & to )
 {
     return error_code( ::MoveFileA( from.c_str(), to.c_str() )
       ? 0 : ::GetLastError(), system_category );
 }
 }}}


 {{{
 BOOST_FILESYSTEM_DECL error_code
 rename_api( const std::string & from, const std::string & to )
 {
    // POSIX is too permissive so must check
    error_code dummy;
    if ( fs::exists( status_api( to, dummy ) ) )
      return error_code( EEXIST, system_category );
    return error_code( std::rename( from.c_str(), to.c_str() ) != 0
      ? errno : 0, system_category );
 }

 }}}

 And boost/filesystem/operation.hpp


 {{{
 BOOST_FS_FUNC(void) rename( const Path & from_path, const Path & to_path )
 {
   system::error_code ec( detail::rename_api(
     from_path.external_directory_string(),
     to_path.external_directory_string() ) );
   if ( ec )
     boost::throw_exception( basic_filesystem_error<Path>(
       "boost::filesystem::rename",
       from_path, to_path, ec ) );
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2866>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC