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 ; }
void logical_directory_cpi_impl::sync_exists(bool& exists, saga::url url) { // SAGA_ADAPTOR_THROW ("Not implemented! sync_exists", saga::NotImplemented); SAGA_LOG_DEBUG("sync_exists()"); check_state(); saga::url irods_url_org; this->sync_get_cwd(irods_url_org); // to get rid of the /. at the end... std::string irods_path = irods_url_org.get_path(); std::string check_path; boost::filesystem::path i_path(url.get_path()); if (i_path.has_root_path()){ check_path = url.get_path(); } else { check_path = irods_url_org.get_path() + "/" + url.get_path(); } // to get rid of the / at the end the check_path if (check_path.substr(check_path.size()-1,1) == "/"){ check_path.erase(check_path.size()-1); // std::cout << "check_path.erased:" << check_path << std::endl; } try { exists = irdsdir.exists(check_path); std::string str_buf = "check_path:" + check_path; SAGA_LOG_CRITICAL(str_buf.c_str()); } catch (boost::system::system_error const& e) { SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess); } }
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 ; }
/////////////////////////////////////////////////////////////////////////////// // namespace_directory functions /////////////////////////////////////////////////////////////////////////////// // void logical_directory_cpi_impl::sync_change_dir(saga::impl::void_t&, saga::url name) { // SAGA_ADAPTOR_THROW ("Not implemented! sync_change_dir", saga::NotImplemented); SAGA_LOG_DEBUG("dir, sync_change_dir()"); check_state(); saga::url irods_url_org; this->sync_get_cwd(irods_url_org); // to get rid of the /. at the end... std::string irods_path; boost::filesystem::path i_path(name.get_path()); if (i_path.has_root_path()){ irods_path = name.get_path(); } else { irods_path = irods_url_org.get_path() + "/" + name.get_path(); } try { // std::cout<< "irods_path :" << irods_path << std::endl; irdsdir.change_dir(irods_path); } catch (boost::system::system_error const& e) { SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess); } }
saga::url filesystem_adaptor::make_absolute (const saga::url & base, const saga::url & u) { if ( is_absolute (u) ) { return u; } // relative saga::url ret (base); // copy scheme, host, etc ret.set_path (base.get_path () + "/" + u.get_path ()); return ret; }
void dir_cpi_impl::sync_is_dir (bool & is_dir, saga::url url) { instance_data idata (this); is_dir = false; saga::url dir_url(idata->location_); boost::filesystem::path name (url.get_path(), boost::filesystem::native); boost::filesystem::path path (idata->location_.get_path(), boost::filesystem::native); if ( ! name.has_root_path () ) path /= name; else path = name; if(hdfsExists(fs_, path.string().c_str()) == 0) { //Check to see if it is a directory hdfsFileInfo *info; instance_data idata(this); info = hdfsGetPathInfo(fs_, path.string().c_str()); if(info == NULL) { SAGA_ADAPTOR_THROW("file_cpi_impl::init failed", saga::NoSuccess); } if(info->mKind == kObjectKindDirectory) is_dir = true; hdfsFreeFileInfo(info, 1); } }
void dir_cpi_impl::sync_open_dir (saga::filesystem::directory & ret, saga::url name_to_open, int openmode) { instance_data idata (this); bool exists = false; bool is_dir = false; saga::url file_url(idata->location_); boost::filesystem::path name (name_to_open.get_path(), boost::filesystem::native); boost::filesystem::path path (file_url.get_path(), boost::filesystem::native); if ( ! name.has_root_path () ) { path /= name; file_url.set_path(path.string()); } else { path = name; file_url = saga::url(name.string()); } if(fs_->Exists(path.string().c_str())) { exists = true; //Check to see if it is a directory if(fs_->IsDirectory(path.string().c_str())) is_dir = true; } if ( exists && !is_dir) { SAGA_ADAPTOR_THROW(path.string() + ": doesn't refer to a file object", saga::DoesNotExist); } ret = saga::filesystem::directory (this->get_proxy()->get_session(), file_url.get_url(), openmode); //SAGA_ADAPTOR_THROW ("Not Implemented", saga::NotImplemented); }
void logical_directory_cpi_impl::sync_make_dir(saga::impl::void_t&, saga::url url, int flags) { // SAGA_ADAPTOR_THROW ("Not implemented! sync_make_dir", saga::NotImplemented); SAGA_LOG_DEBUG("dir, sync_make_dir()"); check_state(); saga::url irods_url_org; this->sync_get_cwd(irods_url_org); // to get rid of the /. at the end... std::string irods_path = irods_url_org.get_path(); std::string mkdir_path; boost::filesystem::path i_path(url.get_path()); if (i_path.has_root_path()){ mkdir_path = url.get_path(); } else { mkdir_path = irods_url_org.get_path() + "/" + url.get_path(); } // to get rid of the / at the end the mkdir_path if (mkdir_path.substr(mkdir_path.size()-1,1) == "/"){ mkdir_path.erase(mkdir_path.size()-1); } bool exists = false; try { exists = irdsdir.exists(mkdir_path); } catch (boost::system::system_error const& e) { SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess); } if (exists){ SAGA_ADAPTOR_THROW ("The specified target already exists. ", saga::AlreadyExists); } try { // std::cout<< "mkdir_path :" << mkdir_path << std::endl; irdsdir.make_dir(mkdir_path, flags); } catch (boost::system::system_error const& e) { SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess); } }
void logical_directory_cpi_impl::sync_is_entry(bool& is_entry, saga::url url) { // SAGA_ADAPTOR_THROW ("Not implemented! sync_is_entry", saga::NotImplemented); SAGA_LOG_CRITICAL("call namespace, dir, sync_is_entry()"); SAGA_LOG_DEBUG("sync_is_entry()"); check_state(); saga::url irods_url_org; this->sync_get_cwd(irods_url_org); // to get rid of the /. at the end... std::string irods_path = irods_url_org.get_path(); std::string check_path; boost::filesystem::path i_path(url.get_path()); if (i_path.has_root_path()){ check_path = url.get_path(); } else { check_path = irods_url_org.get_path() + "/" + url.get_path(); } // to get rid of the / at the end the check_path if (check_path.substr(check_path.size()-1,1) == "/"){ check_path.erase(check_path.size()-1); } bool exists = false; try { exists = irdsdir.exists(check_path); } catch (boost::system::system_error const& e) { SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess); } if (!exists){ SAGA_ADAPTOR_THROW ("The specified entry does not exist. ", saga::DoesNotExist); } try { is_entry = irdsdir.is_entry(check_path); } catch (boost::system::system_error const& e) { SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess); } }
void logical_directory_cpi_impl::sync_remove(saga::impl::void_t&, saga::url url, int flags) { // SAGA_ADAPTOR_THROW ("Not implemented! sync_remove", saga::NotImplemented); SAGA_LOG_DEBUG("dir, sync_remove(src, dst, flags)"); check_state(); saga::url irods_url_org; this->sync_get_cwd(irods_url_org); // to get rid of the /. at the end... std::string irods_path = irods_url_org.get_path(); std::string rm_path; boost::filesystem::path i_path(url.get_path()); if (i_path.has_root_path()){ rm_path = url.get_path(); } else { rm_path = irods_url_org.get_path() + "/" + url.get_path(); } // to get rid of the / at the end the rm_path if (rm_path.substr(rm_path.size()-1,1) == "/"){ rm_path.erase(rm_path.size()-1); } bool exists = false; try { exists = irdsdir.exists(rm_path); } catch (boost::system::system_error const& e) { SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess); } if (!exists){ SAGA_ADAPTOR_THROW ("The specified source entry does not exist. ", saga::DoesNotExist); } try { // std::cout << "rm_path=" << rm_path << std::endl; irdsdir.remove(rm_path, flags); } catch (boost::system::system_error const& e) { SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess); } }
bool check_job_contact(saga::url& mail_uri) const { if (mail_uri.get_scheme() != "mailto" || mail_uri.get_path().empty() // TODO mail address format check. ) { return false; } return true; }
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 ; }
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; }
void dir_cpi_impl::sync_remove (saga::impl::void_t & ret, saga::url url, int flags) { instance_data idata (this); saga::url dir_url(idata->location_); boost::filesystem::path src_location (idata->location_.get_path(), boost::filesystem::native); // complete paths boost::filesystem::path src_path (url.get_path(), boost::filesystem::native); if ( ! src_path.has_root_path () ) src_location /= src_path; else src_location = src_path; bool is_src_dir = false; if(hdfsExists(fs_, src_location.string().c_str()) != 0) { SAGA_ADAPTOR_THROW("directory::remove: Can't remove directory: " "Does not exist", saga::DoesNotExist); } else { hdfsFileInfo *info; info = hdfsGetPathInfo(fs_, src_location.string().c_str()); if(info == NULL) { SAGA_ADAPTOR_THROW("file_cpi_impl::init failed", saga::NoSuccess); } if(info->mKind == kObjectKindDirectory) is_src_dir = true; else is_src_dir = false; hdfsFreeFileInfo(info, 1); } if (is_src_dir) { if (saga::name_space::Recursive != flags) { SAGA_ADAPTOR_THROW("directory::remove: Can't remove directory. " "Please use recursive mode!", saga::BadParameter); } else { saga_hdfs_delete(fs_, src_location.string().c_str()); } } else { saga_hdfs_delete(fs_, src_location.string().c_str()); } }
void dir_cpi_impl::sync_open (saga::filesystem::file & ret, saga::url name, int openmode) { // SAGA_ADAPTOR_THROW ("Not Implemented", saga::NotImplemented); SAGA_LOG_DEBUG("dir, sync_open()"); check_state(); SAGA_LOG_CRITICAL("call namespace, dir, sync_open()"); saga::url irods_url_org; this->sync_get_cwd(irods_url_org); // to get rid of the /. at the end... std::string str_buf = "irods_url_org: " + irods_url_org.get_string(); SAGA_LOG_CRITICAL(str_buf.c_str()); std::string irods_path; boost::filesystem::path i_path(name.get_path()); if (i_path.has_root_path()){ irods_path = name.get_path(); } else { irods_path = irods_url_org.get_path() + "/" + name.get_path(); } saga::url open_url; this->sync_get_cwd(open_url); // to get rid of the /. at the end... open_url.set_path(irods_path); str_buf = "open_url: " + open_url.get_string(); SAGA_LOG_CRITICAL(str_buf.c_str()); saga::filesystem::file file(open_url, openmode); ret = file; }
void dir_cpi_impl::sync_exists (bool & exists, saga::url url) { instance_data idata (this); saga::url dir_url(idata->location_); boost::filesystem::path name (url.get_path(), boost::filesystem::native); boost::filesystem::path path (idata->location_.get_path(), boost::filesystem::native); if ( ! name.has_root_path () ) path /= name; else path = name; exists = false; if(hdfsExists(fs_, path.string().c_str()) == 0) { exists = true; } }
void dir_cpi_impl::sync_make_dir (saga::impl::void_t & ret, saga::url url, int flags) { instance_data idata (this); // verify current working directory is local saga::url dir_url(idata->location_); boost::filesystem::path src_location (idata->location_.get_path(), boost::filesystem::native); // complete paths boost::filesystem::path src_path (url.get_path(), boost::filesystem::native); if ( ! src_path.has_root_path () ) src_location /= src_path; else src_location = src_path; if(hdfsCreateDirectory(fs_, src_location.string().c_str()) != 0) { SAGA_ADAPTOR_THROW("Could not create directory", saga::NoSuccess); } }
void dir_cpi_impl::sync_copy (saga::impl::void_t & ret, saga::url src, saga::url dst, int flags) { instance_data idata (this); saga::url url(idata->location_); // handle the files boost::filesystem::path src_location (idata->location_.get_path(), boost::filesystem::native); boost::filesystem::path dst_location (src_location); // complete paths boost::filesystem::path src_path (src.get_path(), boost::filesystem::native); boost::filesystem::path dest_path (dst.get_path(), boost::filesystem::native); if ( ! src_path.has_root_path () ) src_location /= src_path; else src_location = src_path; if ( ! dest_path.has_root_path () ) dst_location /= dest_path; else dst_location = dest_path; bool is_src_dir = false; if(hdfsExists(fs_, src_location.string().c_str()) == 0) { //Check to see if it is a directory hdfsFileInfo *info; info = hdfsGetPathInfo(fs_, src_location.string().c_str()); if(info == NULL) { SAGA_ADAPTOR_THROW("file_cpi_impl::init failed", saga::NoSuccess); } if(info->mKind == kObjectKindDirectory) is_src_dir = true; hdfsFreeFileInfo(info, 1); } // src location refers to a is a directory if (is_src_dir) { SAGA_ADAPTOR_THROW("Cannot copy directory at moment.", saga::NotImplemented); } else { //Check to see if dst_location is a directory bool is_dst_dir = false; bool dst_exists = false; if(hdfsExists(fs_, dst_location.string().c_str()) == 0) { dst_exists = true; //Check to see if it is a directory hdfsFileInfo *info; info = hdfsGetPathInfo(fs_, dst_location.string().c_str()); if(info == NULL) { SAGA_ADAPTOR_THROW("file_cpi_impl::init failed", saga::NoSuccess); } if(info->mKind == kObjectKindDirectory) is_dst_dir = true; hdfsFreeFileInfo(info, 1); } else { SAGA_ADAPTOR_THROW("Path does not exists!", saga::NoSuccess); } if (is_dst_dir) dst_location /= src_location.leaf(); // remove the file/directory if it exists and we should overwrite if ((flags & saga::name_space::Overwrite) && dst_exists) { /* if (is_dst_dir) fs::remove_all(dst_location);*/ saga_hdfs_delete(fs_, dst_location.string().c_str()); } if(hdfsExists(fs_, dst_location.string().c_str()) == 0) { SAGA_OSSTREAM strm; strm << "namespace_dir_cpi_impl<Base>::sync_copy: " "target file already exists: " << dst.get_url(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::AlreadyExists); } if(hdfsCopy(fs_, src_location.string().c_str(), fs_, dst_location.string().c_str()) != 0) { SAGA_OSSTREAM strm; strm << "namespace_dir_cpi_impl<Base>::sync_copy: " "target file did not copy successfully: " << dst.get_url(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::NoSuccess); } } }
void file_cpi_impl::sync_copy (saga::impl::void_t & ret, saga::url dest, int flags) { adaptor_data_t adata (this); file_instance_data_t idata (this); // check preconditions // We can only check coditions for local targets if ( saga::adaptors::utils::is_local_address (dest) ) { saga::filesystem::directory loc ("/"); if ( loc.exists (dest.get_path ()) ) { if ( ! (flags & saga::name_space::Overwrite) ) { std::stringstream ss; ss << "Target exists: " << dest; SAGA_ADAPTOR_THROW (ss.str (), saga::AlreadyExists); } } } std::string src (u_.get_string ()); std::string tgt (dest.get_string ()); CURLcode code; // get handle for input and output curl ops (see README) CURL * in = adata->get_curl_handle_in (); CURL * out = adata->get_curl_handle_out (); // create buffer file FILE * buf = ::fopen ("/tmp/curl-cache.dat", "w+"); ensure (NULL != buf, "fopen() failed: ", ::strerror (errno)); // read data into buffer code = curl_easy_setopt (in, CURLOPT_URL, src.c_str ()); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_setopt (in, CURLOPT_WRITEDATA, buf); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_perform (in); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); // data are in buffer - now rewind buffer, and copy data to target location ::rewind (buf); code = curl_easy_setopt (out, CURLOPT_URL, tgt.c_str ()); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_setopt (out, CURLOPT_VERBOSE, "true"); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_setopt (out, CURLOPT_USERPWD, "merzky:Z(I)nfandel"); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_setopt (out, CURLOPT_UPLOAD, "true"); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_setopt (out, CURLOPT_READDATA, buf); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_perform (out); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); ::fclose (buf); // done :-) }
inline void remove_drive(saga::url& u) { std::string p(u.get_path()); if (p.size() >= 2 && std::isalpha(p[0]) && p[1] == ':') u.set_path(p.substr(2)); }
void dir_cpi_impl::sync_move (saga::impl::void_t & ret, saga::url src, saga::url dest, int flags) { instance_data idata (this); // verify current working directory is local saga::url url(idata->location_); // handle the files boost::filesystem::path src_location (idata->location_.get_path(), boost::filesystem::native); boost::filesystem::path dst_location (src_location); // complete paths boost::filesystem::path src_path (src.get_path(), boost::filesystem::native); boost::filesystem::path dest_path (dest.get_path(), boost::filesystem::native); if ( ! src_path.has_root_path () ) src_location /= src_path; else src_location = src_path; if ( ! dest_path.has_root_path () ) dst_location /= dest_path; else dst_location = dest_path; bool is_src_dir; bool is_dst_dir; if(hdfsExists(fs_, src_location.string().c_str()) == 0) { //Check to see if it is a directory hdfsFileInfo *info; info = hdfsGetPathInfo(fs_, src_location.string().c_str()); if(info == NULL) { SAGA_ADAPTOR_THROW("file_cpi_impl::init failed", saga::NoSuccess); } if(info->mKind == kObjectKindDirectory) is_src_dir = true; else is_src_dir = false; hdfsFreeFileInfo(info, 1); } bool dst_exists = false; if(hdfsExists(fs_, dst_location.string().c_str()) == 0) { dst_exists = true; //Check to see if it is a directory hdfsFileInfo *info; info = hdfsGetPathInfo(fs_, dst_location.string().c_str()); if(info == NULL) { SAGA_ADAPTOR_THROW("file_cpi_impl::init failed", saga::NoSuccess); } if(info->mKind == kObjectKindDirectory) is_dst_dir = true; else is_dst_dir = false; hdfsFreeFileInfo(info, 1); } if (!is_src_dir && is_dst_dir) dst_location /= src_location.leaf(); if ((flags & saga::name_space::Overwrite) && dst_exists) { /* if (is_dst_dir) fs::remove_all(dst_location);*/ saga_hdfs_delete(fs_, dst_location.string().c_str()); } // if destination still exists raise an error dst_exists = false; if(hdfsExists(fs_, dst_location.string().c_str()) == 0) { SAGA_OSSTREAM strm; strm << "namespace_dir_cpi_impl<Base>::sync_move: " "target file already exists: " << dest.get_url(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::AlreadyExists); } if(hdfsMove(fs_, src_location.string().c_str(), fs_, dst_location.string().c_str()) != 0) { SAGA_ADAPTOR_THROW("Unable to move files", saga::NoSuccess); } }