Beispiel #1
0
  bool dir_cpi_impl::resolve( saga::url const &url_, std::string &ret )
  {
    std::string temp = url_.get_host() ; 

    if( temp.empty() )
    {

       if( (! ( url_.get_path()).empty() ))
       {
           ret = url_.get_path() ; 

           if ( url_.get_scheme().empty() &&
                url_.get_host().empty()   &&
                url_.get_path ()[0] != '/' )
           {
              return true ;      
           }

           return false ;    
      }

    }

    ret = temp ; 

    return false ; 
  }
Beispiel #2
0
  void dir_cpi_impl::sync_open (saga::filesystem::file & ret, 
                                saga::url                name, 
                                int                      openmode)
  {
    
    std::string to_open ; 
    
    /* If it is a relative path, then 
     * construct the appropriate URL and
     * create the file in the same session
     */
    if ( name.get_scheme().empty() &&
         name.get_host().empty()   &&
         name.get_path()[0] != '/' )
    {
       to_open += "sector://" ; 
       to_open += dir_ ; 
       to_open += '/' ; 
       to_open += name.get_path() ; 
       ret = saga::filesystem::file (s_, saga::url(to_open), openmode ) ; 
       return ; 
    }

    ret = saga::filesystem::file ( s_, name, openmode ) ; 
    return ; 

  }
 bool filesystem_adaptor::is_absolute (const saga::url & u)
 {
   if ( u.get_scheme   ().empty ()  &&
        u.get_host     ().empty ()  &&
        u.get_username ().empty ()  &&
        u.get_password ().empty ()  &&
        u.get_port     ()    == -1  &&
        u.get_path     ()[0] != '/' )
   {
     return false;
   }
   
   return true;
 }
  std::string filesystem_adaptor::get_sshfs_id (const saga::url & u)
  {
    std::string host = u.get_host     ();
    int         port = u.get_port     ();
    std::string user = u.get_username ();

    std::stringstream ss;

    if ( ! user.empty () )   ss << user << "@" ;
    if ( ! host.empty () )   ss << host;
    if ( port == -1      )   ss << ":"  << 22  ;
    else                     ss << ":"  << port;

    return ss.str ();
  }
//// connection pool handling - remove a handle //////////////////////////////
//
void adaptor::removeConnectionHandle (const saga::url url)
{
    // extract protocol, server & port from given url
    std::string location("");
    location.append(url.get_scheme());
    location.append("://");
    location.append(url.get_host());
    
    if( RLSConnectionPool_ == NULL )
    {
        return;
    }
    else
    {
        RLSConnectionPool_->erase(location);
    }
}
Beispiel #6
0
  void dir_cpi_impl::sync_open_dir (saga::filesystem::directory & ret, 
                                    saga::url                     name, 
                                    int                           openmode)
  {

    std::string to_open ; 

    if ( name.get_scheme().empty() &&
         name.get_host().empty()   &&
         name.get_path ()[0] != '/' )
    {
       to_open += "sector://" ; 
       to_open += dir_ ; 
       to_open += '/' ; 
       to_open += name.get_path() ; 
       ret = saga::filesystem::directory ( s_, saga::url (to_open), openmode ) ; 
       return ; 
    }

    ret = saga::filesystem::directory (s_,  name, openmode ) ; 
    return ; 

  }
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);  
    }
    
}