Exemplo n.º 1
0
///////////////////////////////////////////////////////////////////////////////
// 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);
	}

}
Exemplo n.º 2
0
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);
	}
}
Exemplo n.º 3
0
std::vector <std::string> irods_dir::list(const std::string& irods_url, std::string pattern, int flags)
{
    SAGA_LOG_DEBUG("irods_file_adaptor::api::irods_dir::list");
    SAGA_LOG_CRITICAL("-------------- list entries -----------------\n");
    SAGA_LOG_CRITICAL("-------------- list entries (data) -----------------\n");

    std::string sql_str_data = "\"SELECT DATA_NAME  WHERE COLL_NAME = ";
    sql_str_data += "'" + irods_url + "'";
    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 <std::string> results_data;
//		std::vector <irdEnt_t*> irds_data;
    std::vector <irdEnt_t> irds_data;
    irds_data = icmd.iquest(argc, argv);

    for ( unsigned int i = 0; i < irds_data.size (); i++ )
    {
//			results_data.push_back(irds_data[i]->dataName);
        results_data.push_back(irds_data[i].dataName);
    }


    SAGA_LOG_CRITICAL("-------------- list entries (coll) -----------------\n");

    std::string sql_str_coll = "\"SELECT COLL_NAME  WHERE COLL_NAME like ";
    sql_str_coll += "'" + irods_url + "/%'";
    sql_str_coll += " AND COLL_NAME not like ";
    sql_str_coll += "'" + irods_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 <std::string> results_coll;
//		std::vector <irdEnt_t*> irds_coll;
    std::vector <irdEnt_t> irds_coll;
    irds_coll = icmd.iquest(argc2, argv2);

    for ( unsigned int i = 0; i < irds_coll.size (); i++ )
    {
//			boost::filesystem::path i_path(irds_coll[i]->collName);
        boost::filesystem::path i_path(irds_coll[i].collName);
        results_coll.push_back(i_path.leaf());
    }

    std::vector <std::string> results;
    results = results_data;
    results.insert(results.end(), results_coll.begin(), results_coll.end());

    return results;

}
Exemplo n.º 4
0
void TorrentFile::init(const std::string & path, bool files_should_exists, uint32_t & files_exists)
{
	if (path == "" || path[0] != '/')
		throw Exception(Exception::ERR_CODE_UNDEF);

	std::string i_path(path);
	if (i_path[i_path.length() - 1] != '/')
		i_path.append("/");

	uint32_t files_count = m_torrent->get_files_count();

	if (files_count > 1)
	{
		m_torrent->get_dirtree().make_dir_tree(i_path);
		i_path.append(m_torrent->get_name() + "/");
	}
	files_exists = 0;
	for(uint32_t i = 0; i < files_count; i++)
	{
		info::file_stat * fi = m_torrent->get_file_info(i);
		file f;
		f.length = fi->length;
		f.name = i_path + fi->path;
		f.download = true;
		f.priority = DOWNLOAD_PRIORITY_NORMAL;
		f.downloaded = 0;
		try
		{
			if (m_fm->File_exists(f.name, f.length))
				files_exists++;
			m_fm->File_add(f.name, f.length, false, shared_from_this(), f.file_);
		}
		catch(Exception & e)
		{
			ReleaseFiles();
			files_exists = 0;
			throw Exception(Exception::ERR_CODE_UNDEF);
		}
		catch (SyscallException & e)
		{
			ReleaseFiles();
			files_exists = 0;
			throw SyscallException(e);
		}
		catch(...)
		{
			ReleaseFiles();
			files_exists = 0;
			throw Exception(Exception::ERR_CODE_UNDEF);
		}
		m_files.push_back(f);
	}
}
Exemplo n.º 5
0
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);
	}
}
Exemplo n.º 6
0
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);
	}
}
Exemplo n.º 7
0
int TorrentFile::Init(Torrent * t, std::string & path,bool _new)
{
	//std::cout<<"TorrentFile created\n";
	if (t == NULL || path == "" || path[0] != '/')
		return ERR_BAD_ARG;
	m_piece_for_check_hash = new(std::nothrow) char[t->m_piece_length];
	if (m_piece_for_check_hash == NULL)
	{
		t->m_error = GENERAL_ERROR_NO_MEMORY_AVAILABLE;
		return ERR_SYSCALL_ERROR;
	}

	m_torrent = t;
	m_fm = t->m_fm;
	m_pieces_count = t->m_piece_count;
	m_piece_length = t->m_piece_length;
	m_files_count  = t->m_files_count;
	m_length = t->m_length;
	m_pieces = new unsigned char*[m_pieces_count];
	for(uint32_t i = 0; i < m_pieces_count; i++)
	{
		m_pieces[i]=new unsigned char[20];
		memcpy(m_pieces[i], &t->m_pieces[i*20], 20);
	}

	m_files = new file_info[m_files_count];
	std::string i_path(path);
	if (i_path[i_path.length() - 1] != '/')
		i_path.append("/");
	//std::cout<<i_path<<std::endl;
	for(uint32_t i = 0; i < m_files_count; i++)
	{
		m_files[i].length = t->m_files[i].length;
		int l = strlen(t->m_files[i].name) + i_path.length();
		m_files[i].name = new char[l + 1];// + \0
		memset(m_files[i].name, 0, l + 1);
		strncat(m_files[i].name, i_path.c_str(), i_path.length());
		strncat(m_files[i].name, t->m_files[i].name, strlen(t->m_files[i].name));
		m_files[i].download = t->m_files[i].download;
		//std::cout<<i<<" "<<m_files[i].name<<std::endl;
		m_files[i].fm_id = m_fm->File_add(m_files[i].name, m_files[i].length, false, t);
	}
	build_piece_offset_table();
	return ERR_NO_ERROR;
}
Exemplo n.º 8
0
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);
	}
}
Exemplo n.º 9
0
  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;
  }