bool FileSystem::CopyFileFromTo(const string& source, const string& destination) { if (source == destination) return true; // In case the destination path doesn't exist, create it if (!DirectoryExists(GetDirectoryFromFilePath(destination))) { CreateDirectory_(GetDirectoryFromFilePath(destination)); } try { return copy_file(source, destination, copy_options::overwrite_existing); } catch (filesystem_error& e) { LOG_ERROR("FileSystem: Could not copy \"" + source + "\". " + string(e.what())); return true; } }
void create_directory(std::string const& f, error_code& ec) { ec.clear(); #if defined TORRENT_WINDOWS && TORRENT_USE_WSTRING #define CreateDirectory_ CreateDirectoryW std::wstring n = convert_to_wstring(f); #else #define CreateDirectory_ CreateDirectoryA std::string n = convert_to_native(f); #endif #ifdef TORRENT_WINDOWS if (CreateDirectory_(n.c_str(), 0) == 0 && GetLastError() != ERROR_ALREADY_EXISTS) ec.assign(GetLastError(), boost::system::get_system_category()); #else int ret = mkdir(n.c_str(), 0777); if (ret < 0 && errno != EEXIST) ec.assign(errno, boost::system::get_generic_category()); #endif }