Пример #1
0
TEST_F(FileTransferTest, Test1) {
  const int kFileSize = CheckBook::GetSliceSize() + 1;
  string content;
  CreateFile(kFileSize, &content);
  const string local_filename = "1112";
  FileTransfer::RegisterRequest request;
  FileTransfer::RegisterResponse response;
  request.set_src_filename(kTestFile);
  request.set_local_filename(local_filename);
  request.set_local_mac_address(GetMacAddress());
  RpcController controller;
  scoped_ptr<FileTransferServiceImpl> local_file_transfer_service(
      new FileTransferServiceImpl(FLAGS_local_root));
  scoped_ptr<FileDownloadNotifyImpl> local_file_notify(
      new FileDownloadNotifyImpl);
  client_connection_->RegisterService(local_file_transfer_service.get());
  client_connection_->RegisterService(local_file_notify.get());
  boost::shared_ptr<FileDownloadNotifier> notifier(
      new FileDownloadNotifier("Test1Notifier"));
  local_file_notify->RegisterNotifier(kTestFile, local_filename, notifier);
  CHECK(!client_connection_->IsConnected());
  CHECK(client_connection_->Connect());
  client_stub_->RegisterDownload(
      &controller,
      &request, &response, NULL);
  controller.Wait();
  ASSERT_TRUE(response.succeed());
  notifier->Wait();
  client_connection_->Disconnect();
  boost::filesystem::path dest_path(FLAGS_local_root);
  dest_path /= local_filename;
  ASSERT_TRUE(FileEqual(kTestFile, dest_path.file_string()));
  boost::filesystem::remove(kTestFile);
  boost::filesystem::remove(dest_path);
}
Пример #2
0
int SQY_h5_link(const char* pSrcFileName,
        const char* pSrcLinkPath,
        const char* pSrcLinkName,
        const char* pTargetFile,
        const char* pTargetDatasetPath,
        const char* pTargetDatasetName	){
  int rvalue = 1;
  //  H5::Exception::dontPrint();

  bfs::path src_p = pSrcFileName;
  sqy::h5_file src(src_p, bfs::exists(src_p) ? H5F_ACC_RDWR : H5F_ACC_TRUNC);
  std::stringstream src_path("");
  src_path << pSrcLinkPath << "/" << pSrcLinkName;

  bfs::path dst_p = pTargetFile;
  sqy::h5_file dest(dst_p);
  std::stringstream dest_path("");
  dest_path << pTargetDatasetPath << "/" << pTargetDatasetName;

  if(dest.has_h5_item(dest_path.str()))
    rvalue = src.setup_link(src_path.str(),dest,dest_path.str());
  else
    rvalue = 1;

  return rvalue;
}
Пример #3
0
Py::Object pysvn_client::cmd_export( const Py::Tuple &a_args, const Py::Dict &a_kws )
{
    static argument_description args_desc[] =
    {
    { true,  name_src_url_or_path },
    { true,  name_dest_path },
    { false, name_force },
    { false, name_revision },
#if defined( PYSVN_HAS_CLIENT_EXPORT2 )
    { false, name_native_eol },
#endif
#if defined( PYSVN_HAS_CLIENT_EXPORT3 )
    { false, name_ignore_externals },
    { false, name_recurse },
    { false, name_peg_revision },
#endif
#if defined( PYSVN_HAS_CLIENT_EXPORT4 )
    { false, name_depth },
#endif
    { false, NULL }
    };
    FunctionArguments args( "export", args_desc, a_args, a_kws );
    args.check();

    std::string src_path( args.getUtf8String( name_src_url_or_path ) );
    std::string dest_path( args.getUtf8String( name_dest_path ) );
    bool is_url = is_svn_url( src_path );

    bool force = args.getBoolean( name_force, false );
    svn_opt_revision_t revision;
    if( is_url )
         revision = args.getRevision( name_revision, svn_opt_revision_head );
    else
         revision = args.getRevision( name_revision, svn_opt_revision_working );

#if defined( PYSVN_HAS_CLIENT_EXPORT2 )
    const char *native_eol = NULL;
    if( args.hasArg( name_native_eol ) )
    {
        Py::Object native_eol_obj = args.getArg( name_native_eol );
        if( native_eol_obj != Py::None() )
        {
            Py::String eol_py_str( native_eol_obj );
            std::string eol_str = eol_py_str.as_std_string( g_utf_8 );
            if( eol_str == "CR" )
                native_eol = "CR";
            else if( eol_str == "CRLF" )
                native_eol = "CRLF";
            else if( eol_str == "LF" )
                native_eol = "LF";
            else
                throw Py::ValueError( "native_eol must be one of None, \"LF\", \"CRLF\" or \"CR\"" );
        }
    }
#endif
#if defined( PYSVN_HAS_CLIENT_EXPORT3 )
#if defined( PYSVN_HAS_CLIENT_EXPORT4 )
    svn_depth_t depth = args.getDepth( name_depth, name_recurse, svn_depth_infinity, svn_depth_infinity, svn_depth_files );
#else
    bool recurse = args.getBoolean( name_recurse, true );
#endif
    bool ignore_externals = args.getBoolean( name_ignore_externals, false );
    svn_opt_revision_t peg_revision = args.getRevision( name_peg_revision, revision );

    revisionKindCompatibleCheck( is_url, peg_revision, name_peg_revision, name_url_or_path );
#endif

    revisionKindCompatibleCheck( is_url, revision, name_revision, name_url_or_path );

    svn_revnum_t revnum = 0;

    SvnPool pool( m_context );

    try
    {
        std::string norm_src_path( svnNormalisedIfPath( src_path, pool ) );

        checkThreadPermission();

        PythonAllowThreads permission( m_context );

#if defined( PYSVN_HAS_CLIENT_EXPORT4 )
        svn_error_t * error = svn_client_export4
            (
            &revnum,
            norm_src_path.c_str(),
            dest_path.c_str(),
            &peg_revision,
            &revision,
            force,
            ignore_externals,
            depth,
            native_eol,
            m_context,
            pool
            );
#elif defined( PYSVN_HAS_CLIENT_EXPORT3 )
        svn_error_t * error = svn_client_export3
            (
            &revnum,
            norm_src_path.c_str(),
            dest_path.c_str(),
            &peg_revision,
            &revision,
            force,
            ignore_externals,
            recurse,
            native_eol,
            m_context,
            pool
            );
#elif defined( PYSVN_HAS_CLIENT_EXPORT2 )
        svn_error_t * error = svn_client_export2
            (
            &revnum,
            norm_src_path.c_str(),
            dest_path.c_str(),
            &revision,
            force,
            native_eol,
            m_context,
            pool
            );
#else
        svn_error_t * error = svn_client_export
            (
            &revnum,
            norm_src_path.c_str(),
            dest_path.c_str(),
            &revision,
            force,
            m_context,
            pool
            );
#endif
        permission.allowThisThread();
        if( error != NULL )
            throw SvnException( error );
    }
    catch( SvnException &e )
    {
        // use callback error over ClientException
        m_context.checkForError( m_module.client_error );

        throw_client_error( e );
    }

    return Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, revnum ) );
}
Пример #4
0
  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);
     }
  }
Пример #5
0
  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);
        }
     }
  }
Пример #6
0
TEST_F(FileTransferTest, Test2) {
  const int kConnectionNumber = FLAGS_num_connections;
  const int kSliceNumber = 10;
  const int kFileSize = CheckBook::GetSliceSize()  * kSliceNumber + 1;
  string content;
  CreateFile(kFileSize, &content);
  const string local_filename = "111";
  FileTransfer::RegisterRequest request;
  FileTransfer::RegisterResponse response;
  request.set_src_filename(kTestFile);
  request.set_local_filename(local_filename);
  request.set_local_mac_address(GetMacAddress());
  RpcController controller;
  boost::shared_ptr<FileTransferServiceImpl> local_file_transfer_service(
      new FileTransferServiceImpl(FLAGS_local_root));
  boost::shared_ptr<FileDownloadNotifyImpl> local_file_notify(
      new FileDownloadNotifyImpl);
  client_connection_->RegisterService(local_file_transfer_service.get());
  client_connection_->RegisterService(local_file_notify.get());
  boost::shared_ptr<FileDownloadNotifier> notifier(
      new FileDownloadNotifier("FinishedNotify"));
  local_file_notify->RegisterNotifier(
      kTestFile, local_filename, notifier);
  vector<boost::shared_ptr<ClientConnection> > connections;
  for (int i = 0; i < kConnectionNumber; ++i) {
    controller.Reset();
    const string name("FileDownloadTest2Client." + boost::lexical_cast<string>(i));
    boost::shared_ptr<ClientConnection> r(new ClientConnection(name, FLAGS_server, FLAGS_port));
    CHECK(!r->IsConnected());
    CHECK(r->Connect());
    r->RegisterService(local_file_transfer_service.get());
    r->RegisterService(local_file_notify.get());
    connections.push_back(r);
    FileTransfer::FileDownloadService::Stub stub(r.get());
    request.set_peer_name(r->name());
    VLOG(2) << "Call RegisterDownload to register: " << i;
    stub.RegisterDownload(
        NULL,
        &request, &response, NULL);
    VLOG(2) << "Register " << i;
  }
  for (int i = 0; i < connections.size(); ++i) {
    if (i % 2 == 1) {
      VLOG(2) << "Disconnect: " << i << connections[i]->name();
      connections[i]->Disconnect();
      connections.erase(connections.begin() + i);
    }
  }
  ASSERT_LT(connections.size(), kConnectionNumber);
  ASSERT_GT(connections.size(), 0);
  VLOG(2) << "connections size: " << connections.size();
  notifier->Wait();
  for (int i = 0; i < connections.size(); ++i) {
    VLOG(2) << "Disconnect: " << i << connections[i]->name();
    connections[i]->Disconnect();
  }
  boost::filesystem::path dest_path(FLAGS_local_root);
  dest_path /= local_filename;
  ASSERT_TRUE(FileEqual(kTestFile, dest_path.file_string()));
//  boost::filesystem::remove(kTestFile);
//  boost::filesystem::remove(dest_path);
}
Пример #7
0
Py::Object pysvn_client::cmd_move( const Py::Tuple &a_args, const Py::Dict &a_kws )
{
    static argument_description args_desc[] =
    {
    { true,  name_src_url_or_path },
    { true,  name_dest_url_or_path },
    { false, name_force },
    { false, NULL }
    };
    FunctionArguments args( "move", args_desc, a_args, a_kws );
    args.check();

    SvnPool pool( m_context );
    pysvn_commit_info_t *commit_info = NULL;

    std::string type_error_message;
    try
    {
        type_error_message = "expecting string for src_url_or_path (arg 1)";
        Py::String src_path( args.getUtf8String( name_src_url_or_path ) );

        type_error_message = "expecting string for dest_url_or_path (arg 2)";
        Py::String dest_path( args.getUtf8String( name_dest_url_or_path ) );

#ifndef PYSVN_HAS_CLIENT_MOVE2
        svn_opt_revision_t revision;
        revision.kind = svn_opt_revision_head;
#endif

        type_error_message = "expecting boolean for keyword force";
        bool force = args.getBoolean( name_force, false );

        try
        {
            std::string norm_src_path( svnNormalisedIfPath( src_path, pool ) );
            std::string norm_dest_path( svnNormalisedIfPath( dest_path, pool ) );

            checkThreadPermission();

            PythonAllowThreads permission( m_context );

#if defined( PYSVN_HAS_CLIENT_MOVE4 )
            // behavior changed
            svn_error_t *error = svn_client_move4
                (
                &commit_info,
                norm_src_path.c_str(),
                norm_dest_path.c_str(),
                force,
                m_context,
                pool
                );
#elif defined( PYSVN_HAS_CLIENT_MOVE3 )
            svn_error_t *error = svn_client_move3
                (
                &commit_info,               // changed type
                norm_src_path.c_str(),
                norm_dest_path.c_str(),
                force,
                m_context,
                pool
                );
#elif defined( PYSVN_HAS_CLIENT_MOVE2 )
            svn_error_t *error = svn_client_move2
                (
                &commit_info,
                norm_src_path.c_str(),
                norm_dest_path.c_str(),
                force,
                m_context,
                pool
                );
#else
            svn_error_t *error = svn_client_move
                (
                &commit_info,
                norm_src_path.c_str(),
                &revision,
                norm_dest_path.c_str(),
                force,
                m_context,
                pool
                );
#endif
            permission.allowThisThread();
            if( error != NULL )
                throw SvnException( error );
        }
        catch( SvnException &e )
        {
            // use callback error over ClientException
            m_context.checkForError( m_module.client_error );

            throw_client_error( e );
        }
    }
    catch( Py::TypeError & )
    {
        throw Py::TypeError( type_error_message );
    }

    return toObject( commit_info );
}
Пример #8
0
Py::Object pysvn_client::cmd_move2( const Py::Tuple &a_args, const Py::Dict &a_kws )
{
    static argument_description args_desc[] =
    {
    { true, name_sources },
    { true, name_dest_url_or_path },
    { false, name_force },
    { false, name_move_as_child },
    { false, name_make_parents },
    { false, name_revprops },
    { false, NULL }
    };
    FunctionArguments args( "move2", args_desc, a_args, a_kws );
    args.check();

    SvnPool pool( m_context );
    pysvn_commit_info_t *commit_info = NULL;

    std::string type_error_message;
    try
    {
        type_error_message = "expecting list for sources (arg 1)";
        Py::List list_all_sources = args.getArg( name_sources );

        apr_array_header_t *all_sources =
            apr_array_make( pool, list_all_sources.length(), sizeof(const char *) );

        for( unsigned int index=0; index<list_all_sources.length(); index++ )
        {
            type_error_message = "expecting string in sources list";
            Py::String py_src_url_or_path( list_all_sources[ index ] );

            std::string src_url_or_path;
            if( py_src_url_or_path.isUnicode() )
            {
                Py::String utf8( py_src_url_or_path.encode( name_utf8 ) );
                src_url_or_path = py_src_url_or_path.as_std_string();
            }
            else
            {
                src_url_or_path = py_src_url_or_path.as_std_string();
            }

            std::string norm_src_url_or_path( svnNormalisedIfPath( src_url_or_path, pool ) );

            const char *src_path_copy = apr_pstrdup( pool, norm_src_url_or_path.c_str() );

            APR_ARRAY_PUSH( all_sources, const char *) = src_path_copy;
        }

        type_error_message = "expecting string for dest_url_or_path";
        Py::String dest_path( args.getUtf8String( name_dest_url_or_path ) );

        type_error_message = "expecting boolean for keyword force";
        bool force = args.getBoolean( name_force, false );

        type_error_message = "expecting boolean for keyword move_as_child";
        bool move_as_child = args.getBoolean( name_move_as_child, false );

        type_error_message = "expecting boolean for keyword make_parents";
        bool make_parents = args.getBoolean( name_make_parents, false );

        apr_hash_t *revprops = NULL;
        if( args.hasArg( name_revprops ) )
        {
            Py::Object py_revprop = args.getArg( name_revprops );
            if( !py_revprop.isNone() )
            {
                revprops = hashOfStringsFromDistOfStrings( py_revprop, pool );
            }
        }

        try
        {
            std::string norm_dest_path( svnNormalisedIfPath( dest_path, pool ) );

            checkThreadPermission();
            PythonAllowThreads permission( m_context );

            // behavior changed
            svn_error_t *error = svn_client_move5
                (
                &commit_info,
                all_sources,
                norm_dest_path.c_str(),
                force,
                move_as_child,
                make_parents,
                revprops,
                m_context,
                pool
                );
            permission.allowThisThread();
            if( error != NULL )
            {
                throw SvnException( error );
            }
        }
        catch( SvnException &e )
        {
            // use callback error over ClientException
            m_context.checkForError( m_module.client_error );

            throw_client_error( e );
        }
    }
    catch( Py::TypeError & )
    {
        throw Py::TypeError( type_error_message );
    }

    return toObject( commit_info );
}
Пример #9
0
Py::Object pysvn_client::cmd_copy2( const Py::Tuple &a_args, const Py::Dict &a_kws )
{
    static argument_description args_desc[] =
    {
    { true, name_sources },
    { true, name_dest_url_or_path },
    { false, name_copy_as_child },
    { false, name_make_parents },
    { false, name_revprops },
    { false, NULL }
    };
    FunctionArguments args( "copy2", args_desc, a_args, a_kws );
    args.check();

    SvnPool pool( m_context );
    pysvn_commit_info_t *commit_info = NULL;

    std::string type_error_message;
    try
    {
        type_error_message = "expecting list for sources (arg 1)";
        Py::List list_all_sources = args.getArg( name_sources );

        apr_array_header_t *all_sources =
            apr_array_make( pool, list_all_sources.length(), sizeof(svn_client_copy_source_t *) );

        for( unsigned int index=0; index<list_all_sources.length(); index++ )
        {
            Py::Tuple tuple_src_rev_pegrev( list_all_sources[ index ] );

            std::string src_url_or_path;
            svn_opt_revision_t *revision = reinterpret_cast<svn_opt_revision_t *>( apr_palloc( pool, sizeof( svn_opt_revision_t ) ) );
            svn_opt_revision_t *peg_revision = reinterpret_cast<svn_opt_revision_t *>( apr_palloc( pool, sizeof( svn_opt_revision_t ) ) );

            if( tuple_src_rev_pegrev.length() > 3 )
            {
                std::string msg = "copy2() expecting tuple with 2 or 3 values in sources list";
                throw Py::AttributeError( msg );
            }

            type_error_message = "expecting string for 1st tuple value in sources list";
            Py::String py_src_url_or_path( tuple_src_rev_pegrev[0] );
            if( py_src_url_or_path.isUnicode() )
            {
                Py::String utf8( py_src_url_or_path.encode( name_utf8 ) );
                src_url_or_path = py_src_url_or_path.as_std_string();
            }
            else
            {
                src_url_or_path = py_src_url_or_path.as_std_string();
            }
            std::string norm_src_url_or_path( svnNormalisedIfPath( src_url_or_path, pool ) );
            bool is_url = is_svn_url( norm_src_url_or_path );

            if( tuple_src_rev_pegrev.length() >= 2 )
            {
                Py::Object obj( tuple_src_rev_pegrev[1] );

                if( pysvn_revision::check( obj ) )
                {
                    pysvn_revision *rev = static_cast<pysvn_revision *>( obj.ptr() );
                    *revision = rev->getSvnRevision();

                    revisionKindCompatibleCheck( is_url, *revision,
                        "sources list 2nd tuple value", "sources list 1st tuple value" );
                }
                else
                {
                    std::string msg = "copy2() expecting revision for 2nd tuple value in sources list";
                    throw Py::AttributeError( msg );
                }
            }
            else
            {
                if( is_url )
                {
                    revision->kind = svn_opt_revision_head;
                }
                else
                {
                    revision->kind = svn_opt_revision_working;
                }
            }

            if( tuple_src_rev_pegrev.length() >= 3 )
            {
                Py::Object obj( tuple_src_rev_pegrev[2] );

                if( pysvn_revision::check( obj ) )
                {
                    pysvn_revision *rev = static_cast<pysvn_revision *>( obj.ptr() );
                    *peg_revision = rev->getSvnRevision();

                    revisionKindCompatibleCheck( is_url, *peg_revision,
                        "sources list 2nd tuple value", "sources list 1st tuple value" );
                }
                else
                {
                    std::string msg = "copy2() expecting revision for 3rd tuple value in sources list";
                    throw Py::AttributeError( msg );
                }
            }
            else
            {
                *peg_revision = *revision;
            }

            svn_client_copy_source_t *source = reinterpret_cast<svn_client_copy_source_t *>( apr_palloc( pool, sizeof(*source) ) );
            source->path = apr_pstrdup( pool, norm_src_url_or_path.c_str() );
            source->revision = revision;
            source->peg_revision = peg_revision;

            APR_ARRAY_PUSH( all_sources, svn_client_copy_source_t *) = source;
        }

        type_error_message = "expecting string for dest_url_or_path";
        Py::String dest_path( args.getUtf8String( name_dest_url_or_path ) );

        type_error_message = "expecting boolean for keyword copy_as_child";
        bool copy_as_child = args.getBoolean( name_copy_as_child, false );

        type_error_message = "expecting boolean for keyword make_parents";
        bool make_parents = args.getBoolean( name_make_parents, false );

        apr_hash_t *revprops = NULL;
        if( args.hasArg( name_revprops ) )
        {
            Py::Object py_revprop = args.getArg( name_revprops );
            if( !py_revprop.isNone() )
            {
                revprops = hashOfStringsFromDistOfStrings( py_revprop, pool );
            }
        }

        try
        {
            std::string norm_dest_path( svnNormalisedIfPath( dest_path, pool ) );

            checkThreadPermission();

            PythonAllowThreads permission( m_context );

            // behavior changed
            svn_error_t *error = svn_client_copy4
                (
                &commit_info,
                all_sources,
                norm_dest_path.c_str(),
                copy_as_child,
                make_parents,
                revprops,
                m_context,
                pool
                );
            permission.allowThisThread();
            if( error != NULL )
            {
                throw SvnException( error );
            }
        }
        catch( SvnException &e )
        {
            // use callback error over ClientException
            m_context.checkForError( m_module.client_error );

            throw_client_error( e );
        }
    }
    catch( Py::TypeError & )
    {
        throw Py::TypeError( type_error_message );
    }

    return toObject( commit_info );
}
Пример #10
0
Py::Object pysvn_client::cmd_copy( const Py::Tuple &a_args, const Py::Dict &a_kws )
{
    static argument_description args_desc[] =
    {
    { true,  name_src_url_or_path },
    { true,  name_dest_url_or_path },
    { false, name_src_revision },
    { false, NULL }
    };
    FunctionArguments args( "copy", args_desc, a_args, a_kws );
    args.check();

    SvnPool pool( m_context );
    pysvn_commit_info_t *commit_info = NULL;

    std::string type_error_message;
    try
    {
        type_error_message = "expecting string for src_path (arg 1)";
        Py::String src_path( args.getUtf8String( name_src_url_or_path ) );

        type_error_message = "expecting string for dest_path (arg 2)";
        Py::String dest_path( args.getUtf8String( name_dest_url_or_path ) );

        type_error_message = "expecting revision for keyword src_revision";
        svn_opt_revision_t revision;
        if( is_svn_url( src_path ) )
            revision = args.getRevision( name_src_revision, svn_opt_revision_head );
        else
            revision = args.getRevision( name_src_revision, svn_opt_revision_working );

        try
        {
            std::string norm_src_path( svnNormalisedIfPath( src_path, pool ) );
            std::string norm_dest_path( svnNormalisedIfPath( dest_path, pool ) );

            checkThreadPermission();

            PythonAllowThreads permission( m_context );

#if defined( PYSVN_HAS_CLIENT_COPY3 )
            // behavior changed
            svn_error_t *error = svn_client_copy3
                (
                &commit_info,
                norm_src_path.c_str(),
                &revision,
                norm_dest_path.c_str(),
                m_context,
                pool
                );
#elif defined( PYSVN_HAS_CLIENT_COPY2 )
            svn_error_t *error = svn_client_copy2
                (
                &commit_info,       // commit info type changed
                norm_src_path.c_str(),
                &revision,
                norm_dest_path.c_str(),
                m_context,
                pool
                );
#else
            svn_error_t *error = svn_client_copy
                (
                &commit_info,
                norm_src_path.c_str(),
                &revision,
                norm_dest_path.c_str(),
                m_context,
                pool
                );
#endif
            permission.allowThisThread();
            if( error != NULL )
                throw SvnException( error );
        }
        catch( SvnException &e )
        {
            // use callback error over ClientException
            m_context.checkForError( m_module.client_error );

            throw_client_error( e );
        }
    }
    catch( Py::TypeError & )
    {
        throw Py::TypeError( type_error_message );
    }

    return toObject( commit_info );
}