bool irods_dir::exists(const std::string& check_url) { SAGA_LOG_DEBUG("irods_file_adaptor::api::irods_dir::exists"); SAGA_LOG_CRITICAL("-------------- check exists -----------------\n"); SAGA_LOG_CRITICAL("-------------- check exists (data) -----------------\n"); bool check = false; boost::filesystem::path check_url_org(check_url); std::string check_name = check_url_org.leaf(); std::string check_url_bpath = check_url_org.branch_path().string(); std::string sql_str_data = "\"SELECT DATA_NAME, COLL_NAME WHERE COLL_NAME = "; sql_str_data += "'" + check_url_bpath + "'"; sql_str_data += " AND DATA_NAME = "; sql_str_data += "'" + check_name + "'"; sql_str_data += "\""; char* c_sql_data = const_cast<char*>(sql_str_data.c_str()); // std::cout << "c_sql_data:" << c_sql_data << std::endl; int argc = 2; char *argv[2] = {"iquest", c_sql_data}; // std::vector <irdEnt_t*> irds_data; std::vector <irdEnt_t> irds_data; irds_data = icmd.iquest(argc, argv); if (irds_data.size() > 0) { check = true; } SAGA_LOG_CRITICAL("-------------- check exists (coll) -----------------\n"); std::string sql_str_coll = "\"SELECT COLL_NAME WHERE COLL_NAME = "; sql_str_coll += "'" + check_url + "'"; sql_str_coll += "\""; char* c_sql_coll = const_cast<char*>(sql_str_coll.c_str()); // std::cout << "c_sql_coll:" << c_sql_coll << std::endl; int argc2 = 2; char *argv2[2] = {"iquest", c_sql_coll}; // std::vector <irdEnt_t*> irds_coll; std::vector <irdEnt_t> irds_coll; irds_coll = icmd.iquest(argc2, argv2); if (irds_coll.size() > 0) { check = true; } return check; }
saga::off_t irods_file::get_size(const std::string& check_url) { SAGA_LOG_DEBUG("irods_file_adaptor::api::irods_file::get_size"); SAGA_LOG_CRITICAL("-------------- get_size -----------------\n"); saga::off_t data_size = 0; boost::filesystem::path check_url_org(check_url); std::string check_name = check_url_org.leaf(); std::string check_url_bpath = check_url_org.branch_path().string(); std::string sql_str_data = "\"SELECT DATA_NAME, DATA_SIZE WHERE COLL_NAME = "; sql_str_data += "'" + check_url_bpath + "'"; sql_str_data += " AND DATA_NAME = "; sql_str_data += "'" + check_name + "'"; sql_str_data += "\""; char* c_sql_data = const_cast<char*>(sql_str_data.c_str()); // std::cout << "c_sql_data:" << c_sql_data << std::endl; int argc = 2; char *argv[2] = {"iquest", c_sql_data}; // std::vector <irdEnt_t*> irds_data; std::vector <irdEnt_t> irds_data; irds_data = icmd.iquest(argc, argv); if (irds_data.size() == 1){ // data_size = irds_data[0]->dataSize; data_size = irds_data[0].dataSize; } else { data_size = 0; } return data_size; }
logical_file_cpi_impl::logical_file_cpi_impl (proxy* p, cpi_info const& info, saga::ini::ini const& glob_ini, saga::ini::ini const& adap_ini, TR1::shared_ptr<saga::adaptor> adaptor) : base_cpi (p, info, adaptor, cpi::Noflags) { instance_data instanceData(this); set_path_str(instanceData->location_); saga::replica::flags flags = static_cast<saga::replica::flags>(instanceData->mode_); saga::url rns_url_org(instanceData->location_); std::string rns_path = rns_url_org.get_path(); //Check the entry existence bool is_entry = false; try { is_entry = rns_ldir.is_entry(rns_path); } catch (boost::system::system_error const& e) { SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess); } // std::cout<< "is_entry =" << is_entry << std::endl; std::string str_buf; if(is_entry){ // std::cout<< "is_entry" << std::endl; if((flags & saga::filesystem::Create) && (flags & saga::filesystem::Exclusive)){ SAGA_ADAPTOR_THROW ("Create and Exclusive flags are given, but the entry already exists.", saga::AlreadyExists); } else{ str_buf = "entry open OK: " + rns_url_org.get_string(); SAGA_LOG_CRITICAL(str_buf.c_str()); is_opened = true; } } else{ // Check the existence bool exists = false; exists = rns_ldir.exists(rns_path); try { exists = rns_ldir.exists(rns_path); } catch (boost::system::system_error const& e) { SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess); } if(exists){ SAGA_ADAPTOR_THROW("invalid entry name", saga::BadParameter); } else{ if(flags & saga::filesystem::Create){ // Check parent directory bool is_p_dir = false; boost::filesystem::path check_url_org(rns_path); std::string check_url_bpath = check_url_org.branch_path().string(); try { is_p_dir = rns_ldir.is_dir(check_url_bpath); } catch (boost::system::system_error const& e) { SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess); } if(is_p_dir){ str_buf = "call rns_ldir open. : " + rns_url_org.get_string(); SAGA_LOG_CRITICAL(str_buf.c_str()); SAGA_LOG_CRITICAL("But NOT created until adding a location"); // rns_ldir.open(rns_path, flags); is_opened = true; } else { SAGA_ADAPTOR_THROW("parent directory does not exist:" + check_url_bpath, saga::BadParameter); } } else{ SAGA_ADAPTOR_THROW ("the entry does not exist.", saga::DoesNotExist); } } } }