Esempio n. 1
0
  dir_cpi_impl::dir_cpi_impl (proxy                * p,
                              cpi_info       const & info,
                              saga::ini::ini const & glob_ini,
                              saga::ini::ini const & adap_ini,
                              boost::shared_ptr<saga::adaptor> adaptor)

      : directory_cpi (p, info, adaptor, cpi::Noflags)
  {
    directory_instance_data_t d_idata(this);

    set_path_str(d_idata->location_);

    SAGA_LOG_CRITICAL("call namespace, dir, dir_cpi_impl()");
	saga::filesystem::flags flags = static_cast<saga::filesystem::flags>(d_idata->mode_);

	saga::url irods_url_org(d_idata->location_);
	std::string irods_path = irods_url_org.get_path();

	// to get rid of the / at the end the irods_path
	if (irods_path.substr(irods_path.size()-1,1) == "/"){
		irods_path.erase(irods_path.size()-1);
	}

	std::string str_buf = "irods_path =" + irods_path;
	SAGA_LOG_CRITICAL(str_buf.c_str());

	//Check the entry existence
	bool is_dir = false;
	try {
		is_dir = irdsdir.is_dir(irods_path);
	}
	catch (boost::system::system_error const& e) {
		SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess);
	}

	str_buf = "is_dir =" + is_dir;
	SAGA_LOG_CRITICAL(str_buf.c_str());

	if(is_dir){
		SAGA_LOG_CRITICAL("is_dir");
		if((flags & saga::filesystem::Create) && (flags & saga::filesystem::Exclusive)){
			SAGA_ADAPTOR_THROW ("Create and Exclusive flags are given, but the directory already exists.",
					saga::AlreadyExists);
		}
		else{
			str_buf = "dir open OK: " + irods_url_org.get_string();
			SAGA_LOG_CRITICAL(str_buf.c_str());
			is_opened = true;
		}
	}
	else{
		// Check the existence
		bool exists = false;
		exists = irdsdir.exists(irods_path);
		try {
			exists = irdsdir.exists(irods_path);
		}
		catch (boost::system::system_error const& e) {
			SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess);
		}

		if(exists){
			SAGA_ADAPTOR_THROW("Invalid directory name", saga::BadParameter);
		}
		else{
			if(flags & saga::filesystem::Create){
				str_buf = "call irds_dir.open: " + irods_url_org.get_string();
				SAGA_LOG_CRITICAL(str_buf.c_str());
			    irdsdir.open_dir(irods_path, flags);
				is_opened = true;
			}
			else{
				SAGA_ADAPTOR_THROW ("The directory does not exist.", saga::DoesNotExist);
			}
		}

	}
  }
Esempio n. 2
0
    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);
    			}
    		}

    	}
    }