Example #1
0
 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);
     }
 }
Example #2
0
  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()); 
     }
  }
Example #3
0
 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;
    }
 }
int main(int argc, char** argv)
{

try 
{
    std::cout << "If #534 is not fixed, the code below will produce at least an exception. " << std::endl;
    std::cout << "Please check: http://faust.cct.lsu.edu/trac/saga/ticket/534 for details." << std::endl;

    saga::url dir_url("gridftp://qb1.loni.org/home/oweidner");
    saga::name_space::directory ns_dir(dir_url);

	saga::name_space::directory ns_dir2 = ns_dir.open_dir(".ssh");
	saga::name_space::entry ns_entry = ns_dir2.open("known_hosts");
	
    std::cout << "\nPASSED!" << std::endl;
}
catch(saga::exception const & e)
{
    std::cerr << "\nFAILED: " << e.what() << std::endl;
}

}
Example #5
0
  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);
     }
  }
int main(int argc, char** argv)
{

try 
{
    std::cout << "If #531 is not fixed, the code below will produce at least an exception. " << std::endl;
    std::cout << "Please check: http://faust.cct.lsu.edu/trac/saga/ticket/531 for details." << std::endl;

    saga::url dir_url("gridftp://qb1.loni.org/tmp/ole_test");
    saga::filesystem::directory dir(dir_url, saga::filesystem::Create);

    dir.open_dir("another_dir", saga::filesystem::Create);
    dir.open_dir("and_another", saga::filesystem::Create);	
    dir.remove(saga::filesystem::Recursive);

    std::cout << "\nPASSED!" << std::endl;
}
catch(saga::exception const & e)
{
    std::cerr << "\nFAILED: " << e.what() << std::endl;
}

}
int main ()
{
  try 
  {
    // saga::url dir_url("ssh://qb4.loni.org/tmp");
    saga::url dir_url("ssh://qb4.loni.org/tmp");
    saga::filesystem::directory dir(dir_url);

    std::cout << "creating file" << std::endl;
    saga::filesystem::file foo = dir.open("foo", saga::filesystem::Create);

    if ( dir.exists ("foo") )
    {
      std::cout << "foo now exists" << std::endl;
    }
    else
    {
      std::cout << "foo does not exist" << std::endl;
      return -1;
    }

    std::cout << "writing 10 bytes" << std::endl;
    saga::mutable_buffer write_buf(10);
    foo.write(write_buf);

    std::cout << "closing file" << std::endl;
    foo.close();
    
  }
  catch ( const saga::exception & e )
  {
    std::cout << " SAGA exception: " << e.what () << std::endl;
    return -1;
  }

  return 0;
}
Example #8
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) {
    adaptor_data_t            adata (this);
    directory_instance_data_t idata (this);
    
    saga::url dir_url(idata->location_);
    
    std::string host(dir_url.get_host());
    if (host.empty()) {
       SAGA_OSSTREAM strm;
       strm << "dir_cpi_impl::init: cannot handle file: " << dir_url.get_url();
       SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter);
    }
    
    std::string scheme(dir_url.get_scheme());
    if (!scheme.empty() && scheme != "kfs" && scheme != "any") {
       SAGA_OSSTREAM strm;
       strm << "dir_cpi_impl::init: cannot handle file: " << dir_url.get_url();
       SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter);
    }
    
    fs_ = getKfsClientFactory()->GetClient(dir_url.get_host(), dir_url.get_port());
    if(!fs_) {
          SAGA_OSSTREAM strm;
          strm << "Could not connect to host : " << dir_url.get_host();
          strm << "on port " << dir_url.get_port();
          SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::NoSuccess);
    }
    
    // check if file exists AND is a dir (not a file)
    bool exists = false;
    bool is_dir = false;
    if(fs_->Exists(dir_url.get_path().c_str())) {
       exists = true;
       //Check to see if it is a directory
       instance_data idata(this);
       if(fs_->IsDirectory(dir_url.get_path().c_str()))
          is_dir = true;
     }
     saga::filesystem::flags OpenMode = (saga::filesystem::flags)idata->mode_;
     if(exists) {
        if(!is_dir) {
           SAGA_ADAPTOR_THROW ("URL does not point to a directory: " +
                               idata->location_.get_url(), saga::BadParameter);
        }
        else {
           if((OpenMode & saga::filesystem::Create) && (OpenMode & saga::filesystem::Exclusive)) {
               SAGA_ADAPTOR_THROW ("Directory " + idata->location_.get_url() +
                                   " already exists.", saga::AlreadyExists);
           }
        }
     }
     else {
     // !exists
        if(!(OpenMode & saga::filesystem::Create)) {
           SAGA_ADAPTOR_THROW ("Directory does not exist and saga::filesystem::Create flag not given: " +
                               idata->location_.get_url(), saga::DoesNotExist);
        }
        else {
           if(fs_->Mkdir(dir_url.get_path().c_str()) != 0) {
              SAGA_OSSTREAM strm;
              strm << "Could not create directory " << idata->location_.get_path();
              SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::DoesNotExist);
           }
        }
     }
     exists = false;
     is_dir = false;
     //Make sure directory exists
     if(fs_->Exists(dir_url.get_path().c_str()))
        exists = true;
     if ((idata->mode_ & saga::filesystem::Create ||
          idata->mode_ & saga::filesystem::CreateParents) &&
          idata->mode_ & saga::filesystem::Exclusive)
     {
        //Check to see if it is a directory
        if(fs_->IsDirectory(dir_url.get_path().c_str()))
           is_dir = true;
        if(is_dir) {
           SAGA_ADAPTOR_THROW(dir_url.get_path().c_str() + ": already exists",
              saga::AlreadyExists);
        }
     }
     if(!exists) {
        //create directory if needed
       if (idata->mode_ & saga::filesystem::Create) {
          if(fs_->Mkdir(dir_url.get_path().c_str()) != 0) {
             SAGA_OSSTREAM strm;
             strm << "Could not create directory " << idata->location_.get_path();
             SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::DoesNotExist);
          }
       }
     }
    
     // we don't need to create the directory twice
     idata->mode_ &= ~(saga::filesystem::Create | saga::filesystem::CreateParents);
    
     if (idata->mode_ & saga::filesystem::Read || idata->mode_ & saga::filesystem::Write ||
         idata->mode_ & saga::filesystem::ReadWrite) {
        //check to see if it exists and is a direcotory
       exists = false;
       is_dir = false;
       if(fs_->Exists(dir_url.get_path().c_str())) {
          exists = true;
          //Check to see if it is a directory
          if(fs_->IsDirectory(dir_url.get_path().c_str()))
             is_dir = true;
       }
       if (!exists || !is_dir) {
            SAGA_OSSTREAM strm;
            strm << idata->location_.get_path() << ": doesn't refer to a directory object";
            SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter);
       }
    }
    
    if (idata->mode_ & ~(
            saga::filesystem::Create | saga::filesystem::CreateParents |
            saga::filesystem::Exclusive | saga::filesystem::Overwrite |
            saga::filesystem::Read | saga::filesystem::Write | saga::filesystem::ReadWrite
    )) {
       SAGA_ADAPTOR_THROW("Unknown openmode value: " +
          boost::lexical_cast<std::string>(idata->mode_), saga::BadParameter);
    }
    //SAGA_ADAPTOR_THROW ("Not Implemented", saga::NotImplemented);
 }