void dir_cpi_impl::sync_exists (bool & exists, saga::url url) { adaptor_data_t AdaptorData(this); directory_instance_data_t InstanceData(this); this->throw_if_local(InstanceData->location_); this->check_if_open ("dir_cpi_impl::sync_exists", InstanceData->location_); saga::url u = merge_urls(InstanceData->location_.get_url(), url); GridFTPConnection * ConnectionHandle = AdaptorData->getConnectionHandleForURL( u.get_url(), write_log_, logfile_loc_ ); try { exists = ConnectionHandle->exist( u.get_url() ); } catch ( globus_gridftp_file_adaptor::exception const & e ) { error_package ep = globus_gridftp_file_adaptor ::error_default_redirect(e, InstanceData->location_.get_url()); SAGA_OSSTREAM strm; strm << "Could not check if [" << u.get_url() << "] exists. " << ep.error_text; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), ep.saga_error); } }
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 file_cpi_impl::sync_move (saga::impl::void_t & ret, saga::url dest, int flags) { adaptor_data_t AdaptorData(this); file_instance_data_t InstanceData (this); try { sync_copy(ret, dest, flags); } catch(saga::exception const & e) { SAGA_OSSTREAM strm; strm << "Could not move [" << InstanceData->location_ << " -> " << dest << "]. Copying source file failed!"; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), e.get_error()); } try { sync_remove(ret, flags); } catch(saga::exception const & e) { SAGA_OSSTREAM strm; strm << "Could not move [" << InstanceData->location_ << " -> " << dest << "]. Removing source file failed!"; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), e.get_error()); } /// This code tries to generate a proper URL for the moved file /// and sets this instance's location to the new location /// FIXME: is this behaviour ok - spec. doesn't say anything about it? saga::url target = merge_urls(InstanceData->location_.get_url(), dest); try { GridFTPConnection * ConnectionHandle = AdaptorData->getConnectionHandleForURL(InstanceData->location_); 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); } } } catch( curl_file_adaptor::exception const & e ) { //FIXME ??? } InstanceData->location_ = target; // FIXME: is this behaviour ok? }
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); } }