Пример #1
0
rc_t vdi_repo( const Vector * v )
{
    KConfig * cfg;
    rc_t rc = KConfigMake( &cfg, NULL );
    if ( rc == 0 )
    {
        const KRepositoryMgr * repomgr;
        rc = KConfigMakeRepositoryMgrRead( cfg, &repomgr );
        {
            if ( VectorLength( v ) < 2 )
            {
                rc = vdi_repo_all( repomgr, true );
            }
            else
            {
                const String * which_repo = VectorGet( v, 1 );
                if ( which_repo != NULL )
                {
                    int32_t repo_id = index_of_match( which_repo, 4, "user", "site", "remote", "all" );
                    if ( repo_id < 0 || repo_id > 3 )
                        rc = KOutMsg( "unknow repository '%S'", which_repo );
                    else
                        rc = vdi_sub_repo( repomgr, v, which_repo, repo_id );
                }
            }

            KRepositoryMgrRelease( repomgr );
        }
        KConfigRelease ( cfg );
    }
    return rc;
}
Пример #2
0
static rc_t get_cache_path_from_repo_mgr( tool_options * options )
{
    KConfig * cfg;
    rc_t rc = KConfigMake ( &cfg, NULL );
    if ( rc != 0 )
    {
        PLOGERR( klogErr, ( klogErr, rc,
                 "KConfigMake() failed in $(func)", "func=%s", __func__ ) );
    }
    else
    {
        const KRepositoryMgr *repo_mgr;
        rc = KConfigMakeRepositoryMgrRead ( cfg, &repo_mgr );
        if ( rc != 0 )
        {
            PLOGERR( klogErr, ( klogErr, rc,
                     "KConfigMakeRepositoryMgrRead() failed in $(func)", "func=%s", __func__ ) );
        }
        else
        {
            KRepositoryVector repos;
            VectorInit ( &repos, 0, 5 );
            rc = KRepositoryMgrUserRepositories ( repo_mgr, &repos );
            if ( rc != 0 )
            {
                rc = 0; /* we do not have a user-repository, but that is OK, the caller will display the lack of it ... */
            }
            else
            {
                uint32_t idx;
                for ( idx = 0; idx < VectorLength( &repos ) && rc == 0; ++idx )
                {
                    const KRepository *repo = VectorGet( &repos, idx );
                    if ( repo != 0 )
                    {
                        char path[ 4096 ];
                        rc = KRepositoryRoot ( repo, path, sizeof path, NULL );
                        if ( rc != 0 )
                        {
                            PLOGERR( klogErr, ( klogErr, rc,
                                     "KRepositoryRoot( for repo # $(idx) ) failed in $(func)", "idx=%u,func=%s", idx, __func__ ) );
                        }
                        else
                        {
                            bool add = true;
                            if ( options->user_repo_name != NULL )
                            {
                                char name[ 1024 ];
                                rc = KRepositoryName ( repo, name, sizeof name, NULL );
                                if ( rc != 0 )
                                {
                                    PLOGERR( klogErr, ( klogErr, rc,
                                             "KRepositoryName( for repo # $(idx) ) failed in $(func)", "idx=%u,func=%s", idx, __func__ ) );
                                }
                                else
                                    add = string_cmp_1( options->user_repo_name, name );
                            }
                            if ( add )
                            {
                                rc = add_tool_options_path( options, path );
                                if ( options->detailed )
                                    KOutMsg( "source: %s\n", path );
                            }
                        }
                    }
                }
                {
                    rc_t rc2 = KRepositoryVectorWhack ( &repos );
                    if ( rc2 != 0 )
                    {
                        PLOGERR( klogErr, ( klogErr, rc2,
                                 "KRepositoryVectorWhack() failed in $(func)", "func=%s", __func__ ) );
                    }
                }
            }
            {
                rc_t rc2 = KRepositoryMgrRelease ( repo_mgr );
                if ( rc2 != 0 )
                {
                    PLOGERR( klogErr, ( klogErr, rc2,
                             "KRepositoryMgrRelease() failed in $(func)", "func=%s", __func__ ) );
                }
            }
        }
        {
            rc_t rc2 = KConfigRelease ( cfg );
            if ( rc2 != 0 )
            {
                PLOGERR( klogErr, ( klogErr, rc2,
                         "KConfigRelease() failed in $(func)", "func=%s", __func__ ) );
            }
        }
    }
    return rc;
}
Пример #3
0
static rc_t perform( tool_options * options, Args * args )
{
    visit_ctx octx;
    rc_t rc2, rc = KDirectoryNativeDir( &octx.dir );
    if ( rc != 0 )
    {
        PLOGERR( klogErr, ( klogErr, rc,
                 "KDirectoryNativeDir() failed in $(func)", "func=%s", __func__ ) );
    }
    else
    {
        rc = KConfigMake ( &octx.cfg, NULL );
        if ( rc != 0 )
        {
            PLOGERR( klogErr, ( klogErr, rc,
                     "KConfigMake() failed in $(func)", "func=%s", __func__ ) );
        }
        else
        {
            rc = KConfigMakeRepositoryMgrRead ( octx.cfg, &octx.repo_mgr );
            if ( rc != 0 )
            {
                PLOGERR( klogErr, ( klogErr, rc,
                         "KConfigMakeRepositoryMgrRead() failed in $(func)", "func=%s", __func__ ) );
            }
            else
            {
                octx.options = options;
                octx.data = NULL;
                switch( options->main_function )
                {
                    case tf_report  : rc = perform_report( &octx ); break;
                    case tf_rreport : rc = perform_rreport( &octx ); break;
                    case tf_unlock  : rc = perform_unlock( &octx ); break;
                    case tf_clear   : rc = perform_clear( &octx ); break;
                    case tf_enable  : rc = perform_set_disable( &octx, false ); break;
                    case tf_disable : rc = perform_set_disable( &octx, true ); break;
                    case tf_unknown : rc = Usage( args ); break;
                }

                rc2 = KRepositoryMgrRelease ( octx.repo_mgr );
                if ( rc2 != 0 )
                {
                    PLOGERR( klogErr, ( klogErr, rc2,
                             "KRepositoryMgrRelease() failed in $(func)", "func=%s", __func__ ) );
                }
            }

            rc2 = KConfigRelease ( octx.cfg );
            if ( rc2 != 0 )
            {
                PLOGERR( klogErr, ( klogErr, rc2,
                         "KConfigRelease() failed in $(func)", "func=%s", __func__ ) );
            }
        }

        rc2 = KDirectoryRelease( octx.dir );
        if ( rc2 != 0 )
        {
            PLOGERR( klogErr, ( klogErr, rc2,
                     "KDirectoryRelease() failed in $(func)", "func=%s", __func__ ) );
        }
    }
    return rc;
}