void file_cpi_impl::sync_copy (saga::impl::void_t & ret, saga::url dest, int flags) { adaptor_data_t AdaptorData(this); file_instance_data_t InstanceData (this); GridFTPConnection * ConnectionHandle = AdaptorData->getConnectionHandleForURL(InstanceData->location_); saga::url target = merge_urls(InstanceData->location_.get_url(), dest); try { if(ConnectionHandle->exist(target.get_url())) { if(ConnectionHandle->is_dir(target.get_url())) { std::string url_path = target.get_path(); if(url_path.rfind("/") != url_path.length()-1) url_path.append("/"); saga::url this_name; this->sync_get_name(this_name); url_path.append(this_name.get_path()); target.set_path(url_path); } } ConnectionHandle->copy_url(InstanceData->location_.get_url(), target.get_url()); } catch( curl_file_adaptor::exception const & e ) { error_package ep = curl_file_adaptor ::error_default_redirect(e, InstanceData->location_.get_url()); SAGA_OSSTREAM strm; strm << "Could not copy [" << InstanceData->location_ << " -> " << target << "]. " << ep.error_text; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), ep.saga_error); } }
void dir_cpi_impl::sync_copy (saga::impl::void_t & ret, saga::url src, saga::url dst, int flags) { adaptor_data_t AdaptorData(this); directory_instance_data_t InstanceData (this); if(dst.get_scheme().empty() && dst.get_host().empty()) { SAGA_OSSTREAM strm; strm << "Could not copy [" << InstanceData->location_ << " -> " << dst << "]. Please specify scheme and/or hostname."; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } if(dst.get_scheme() == "file") { if(dst.get_host() != "localhost") { SAGA_OSSTREAM strm; strm << "Could not copy [" << InstanceData->location_ << " -> " << dst << "]. If target URL scheme is 'file://', only 'localhost' is accepted as host."; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } // avoid file:// -> file:// copy. if (InstanceData->location_.get_scheme() != "gridftp" && InstanceData->location_.get_scheme() != "gsiftp") { SAGA_OSSTREAM strm; strm << "Cannot copy file [" << InstanceData->location_ << "]. " << "Supported source URL schemes are: gridftp:// and gsiftp://"; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::adaptors::AdaptorDeclined); } } else { if(dst.get_scheme() != "gridftp" && dst.get_scheme() != "gsiftp" ) { SAGA_OSSTREAM strm; strm << "Could not copy [" << InstanceData->location_ << " -> " << dst << "]. Only gridftp:// and gsiftp:// and file:// schemes are supported for target urls."; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } } this->check_if_open ("dir_cpi_impl::sync_copy", InstanceData->location_); saga::url u_src = merge_urls(InstanceData->location_.get_url(), src); saga::url u_dst = merge_urls(InstanceData->location_.get_url(), dst); try { GridFTPConnection * ConnectionHandle = AdaptorData->getConnectionHandleForURL(InstanceData->location_, write_log_, logfile_loc_); if(ConnectionHandle->exist(u_dst.get_url())) { if(ConnectionHandle->is_dir(u_dst.get_url())) { std::string url_path = u_dst.get_path(); if(url_path.rfind("/") != url_path.length()-1) url_path.append("/"); saga::url this_name; this->sync_get_name(this_name); url_path.append(this_name.get_path()); u_dst.set_path(url_path); } } ConnectionHandle->copy_url(u_src.get_url(), u_dst.get_url()); } catch( globus_gridftp_file_adaptor::exception const & e ) { error_package ep = globus_gridftp_file_adaptor ::error_default_redirect(e, u_src.get_url()); SAGA_OSSTREAM strm; strm << "Could not copy [" << u_src << " -> " << u_dst << "]. " << ep.error_text; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), ep.saga_error); } }