Index: operations_posix_windows.cpp =================================================================== RCS file: /cvsroot/boost/boost/libs/filesystem/src/operations_posix_windows.cpp,v retrieving revision 1.21 diff -u -b -B -r1.21 operations_posix_windows.cpp --- operations_posix_windows.cpp 26 Nov 2003 12:45:13 -0000 1.21 +++ operations_posix_windows.cpp 30 Nov 2003 03:22:36 -0000 @@ -165,6 +165,18 @@ return data.cFileName; } + struct handle_wrapper + { + HANDLE handle; + handle_wrapper() + : handle(INVALID_HANDLE_VALUE) {} + ~handle_wrapper() + { + if ( handle != INVALID_HANDLE_VALUE ) + ::CloseHandle(handle); + } + }; + #endif fs::directory_iterator end_itr; @@ -356,6 +368,93 @@ ph, fs::detail::system_error_code() ) ); } + BOOST_FILESYSTEM_DECL bool equivalent( const path &ph1, const path &ph2) + { +# ifdef BOOST_POSIX + struct stat stat1, stat2; + if ( ::stat( ph1.string().c_str(), &stat1 ) != 0 ) + boost::throw_exception + (filesystem_error("boost::filesystem::equivalent", + ph1, + fs::detail::system_error_code()) ); + if ( ::stat( ph2.string().c_str(), &stat1 ) != 0 ) + boost::throw_exception + (filesystem_error("boost::filesystem::equivalent", + ph2, + fs::detail::system_error_code()) ); + return stat1.st_dev == stat2.st_dev + && stat1.st_ino == stat2.st_ino; +# else // BOOST_WINDOWS + handle_wrapper file1, file2; + if ( (file1.handle = + ::CreateFileA(ph1.string().c_str(), 0, + FILE_SHARE_READ | FILE_SHARE_WRITE, + 0, + OPEN_EXISTING, + 0, 0)) == INVALID_HANDLE_VALUE ) + boost::throw_exception + (filesystem_error("boost::filesystem::equivalent", + ph1, + fs::detail::system_error_code()) ); + if ( (file2.handle = + ::CreateFileA(ph2.string().c_str(), 0, + FILE_SHARE_READ | FILE_SHARE_WRITE, + 0, + OPEN_EXISTING, + 0, 0)) == INVALID_HANDLE_VALUE ) + boost::throw_exception + (filesystem_error("boost::filesystem::equivalent", + ph2, + fs::detail::system_error_code()) ); + BY_HANDLE_FILE_INFORMATION info1, info2; + if ( !::GetFileInformationByHandle(file1.handle, &info1) ) + boost::throw_exception + (filesystem_error("boost::filesystem::equivalent", + ph1, + fs::detail::system_error_code()) ); + if ( !::GetFileInformationByHandle(file2.handle, &info2) ) + boost::throw_exception + (filesystem_error("boost::filesystem::equivalent", + ph2, + fs::detail::system_error_code()) ); + return info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber + && info1.nFileIndexHigh == info2.nFileIndexHigh + && info1.nFileIndexLow == info2.nFileIndexLow; +# endif + } + + BOOST_FILESYSTEM_DECL unsigned int link_count( const path &ph ) + { +# ifdef BOOST_POSIX + struct stat path_stat; + if ( ::stat( ph.string().c_str(), &path_stat ) != 0 ) + boost::throw_exception + (filesystem_error("boost::filesystem::link_count", + ph, + fs::detail::system_error_code()) ); + return static_cast(path_stat.st_nlink); +# else // BOOST_WINDOWS + handle_wrapper file; + if ( (file.handle = + ::CreateFileA(ph.string().c_str(), 0, + FILE_SHARE_READ | FILE_SHARE_WRITE, + 0, + OPEN_EXISTING, + 0, 0)) == INVALID_HANDLE_VALUE ) + boost::throw_exception + (filesystem_error("boost::filesystem::equivalent", + ph, + fs::detail::system_error_code()) ); + BY_HANDLE_FILE_INFORMATION info; + if ( !::GetFileInformationByHandle(file.handle, &info) ) + boost::throw_exception + (filesystem_error("boost::filesystem::equivalent", + ph, + fs::detail::system_error_code()) ); + return static_cast(nNumberOfLinks); +# endif + } + BOOST_FILESYSTEM_DECL void create_directory( const path & dir_path ) { # ifdef BOOST_POSIX @@ -461,6 +560,26 @@ boost::throw_exception( filesystem_error( "boost::filesystem::copy_file", from_file_ph, to_file_ph, fs::detail::system_error_code() ) ); + } + + BOOST_FILESYSTEM_DECL void link( const path &existing_ph, + const path &new_ph ) + { +# ifdef BOOST_POSIX + if ( ::link(existing_ph.string().c_str(), + new_ph.string().c_str()) != 0) + boost::throw_exception + (filesystem_error("boost::filesystem::link", + existing_ph, new_ph, + fs::detail::system_error_code() ) ); +# else + if ( !::CreateHardLinkA( new_ph.string().c_str(), + existing_ph.string().c_str() ) ) + boost::throw_exception + (filesystem_error("boost::filesystem::link", + existing_ph, new_ph, + fs::detail::system_error_code() ) ); +# endif } BOOST_FILESYSTEM_DECL path current_path()