Beispiel #1
0
static rc_t vdi_report_repo_vector( const KRepositoryMgr * repomgr, const KRepCategory cat,
                                    int32_t select, bool full )

{
    rc_t rc = 0;
    catfunc f = vdi_get_catfunc( cat );
    if ( f != NULL )
    {
        KRepositoryVector v;
        rc = f( repomgr, &v );
        if ( rc == 0 )
        {
            const char * prefix = KRepCategory_to_prefix( cat );
            uint32_t idx, len = VectorLength( &v );
            bool disabled = KRepositoryMgrCategoryDisabled( repomgr, cat );
            rc = KOutMsg( "repo.%s --> disabled: %s, %d subrepositories )\n", prefix, yes_or_no( disabled ), len );
            for ( idx = 0; rc == 0 && idx < len; ++idx )
            {
                if ( select == idx || !full )
                    rc = vdi_report_repository( VectorGet( &v, idx ), prefix, idx, full );
            }

            KRepositoryVectorWhack( &v );
        }
    }
    return rc;
}
Beispiel #2
0
/* RemoteRepositories
 *  retrieve all remote repositories in a Vector
 */
LIB_EXPORT rc_t CC KRepositoryMgrRemoteRepositories ( const KRepositoryMgr *self,
    KRepositoryVector *remote_repositories )
{
    rc_t rc;

    if ( remote_repositories == NULL )
        rc = RC ( rcKFG, rcMgr, rcAccessing, rcParam, rcNull );
    else
    {
        VectorInit ( remote_repositories, 0, 8 );

        if ( self == NULL )
            rc = RC ( rcKFG, rcMgr, rcAccessing, rcSelf, rcNull );
        else
        {
            const KConfig *kfg = KRepositoryMgrGetROKConfig ( self );

            const KConfigNode *remote;
            rc = KConfigOpenNodeRead ( kfg, & remote, "/repository/remote" );
            if ( rc == 0 )
            {
                rc = KRepositoryMgrCategoryRepositories ( remote, krepRemoteCategory, remote_repositories );
                KConfigNodeRelease ( remote );
                if ( rc == 0 )
                    VectorReorder ( remote_repositories, KRepositorySort, NULL );
            }

            if ( rc != 0 )
                KRepositoryVectorWhack ( remote_repositories );
        }
    }

    return rc;
}
Beispiel #3
0
/* UserRepositories
 *  retrieve all user repositories in a Vector
 */
LIB_EXPORT rc_t CC KRepositoryMgrUserRepositories ( const KRepositoryMgr *self,
    KRepositoryVector *user_repositories )
{
    rc_t rc;

    if ( user_repositories == NULL )
        rc = RC ( rcKFG, rcMgr, rcAccessing, rcParam, rcNull );
    else
    {
        VectorInit ( user_repositories, 0, 8 );

        if ( self == NULL )
            rc = RC ( rcKFG, rcMgr, rcAccessing, rcSelf, rcNull );
        else
        {
            const KConfig *kfg = KRepositoryMgrGetROKConfig ( self );

            const KConfigNode *user;
            rc = KConfigOpenNodeRead ( kfg, & user, "/repository/user" );
            if ( rc == 0 )
            {
                rc = KRepositoryMgrCategoryRepositories ( user, krepUserCategory, user_repositories );
                KConfigNodeRelease ( user );
                if ( rc == 0 )
                    VectorReorder ( user_repositories, KRepositorySort, NULL );
            }

            if ( rc != 0 )
                KRepositoryVectorWhack ( user_repositories );
        }
    }

    return rc;
}
Beispiel #4
0
static rc_t report_repo( visit_ctx * octx, KRepCategory category )
{
    rc_t rc, rc1;
    KRepositoryVector repos;
    const char * hint;

    VectorInit ( &repos, 0, 5 );

    switch ( category )
    {
        case krepUserCategory   : hint = MAIN_CAT_USER;
                                   rc = KRepositoryMgrUserRepositories( octx->repo_mgr, &repos );
                                   break;

        case krepSiteCategory   : hint = MAIN_CAT_SITE;
                                   rc = KRepositoryMgrSiteRepositories( octx->repo_mgr, &repos );
                                   break;

        case krepRemoteCategory : hint = MAIN_CAT_REMOTE;
                                   rc = KRepositoryMgrRemoteRepositories( octx->repo_mgr, &repos );
                                   break;
    }

    if ( rc != 0 )
    {
        if ( rc == SILENT_RC( rcKFG, rcNode, rcOpening, rcPath, rcNotFound ) )
        {
            KOutMsg("\n%s:\n", hint);
            KOutMsg("\tnot found in configuration\n");
            rc = 0;
        }
        else
        {
            PLOGERR( klogErr, ( klogErr, rc,
                 "KRepositoryMgr<$(hint)>repositories() failed in $(func)",
                 "hint=%s,func=%s", hint, __func__ ) );
        }
    }
    else
    {
        uint32_t idx;
        bool disabled = KRepositoryMgrCategoryDisabled ( octx->repo_mgr, category );

        rc = KOutMsg( "\n%s:\n", hint );
        if ( rc == 0 && disabled )
            rc = KOutMsg( "\tglobally disabled\n" );

        for ( idx = 0; idx < VectorLength( &repos ) && rc == 0; ++idx )
        {
            const KRepository *repo = VectorGet( &repos, idx );
            if ( repo != NULL )
            {
                char repo_name[ 1024 ];
                rc = KRepositoryDisplayName ( repo, repo_name, sizeof repo_name, NULL );
                if ( rc != 0 )
                {
                    PLOGERR( klogErr, ( klogErr, rc,
                             "KRepositoryName() for $(hint) failed in $(func)", "hint=%s,func=%s", hint, __func__ ) );
                }
                else
                {
                    KRepSubCategory sub_cat = KRepositorySubCategory ( repo );
                    bool disabled = KRepositoryDisabled ( repo );
                    bool cache_enabled = KRepositoryCacheEnabled ( repo );
                    const char * sub_cat_ptr = SUB_CAT_UNKNOWN;
                    switch( sub_cat )
                    {
                        case krepMainSubCategory        : sub_cat_ptr = SUB_CAT_MAIN; break;
                        case krepAuxSubCategory         : sub_cat_ptr = SUB_CAT_AUX; break;
                        case krepProtectedSubCategory   : sub_cat_ptr = SUB_CAT_PROT; break;
                        default                         : sub_cat_ptr = SUB_CAT_UNKNOWN; break;
                    }

                    rc = KOutMsg( "\t%s.%s: %s, cache-%s",
                            sub_cat_ptr, repo_name,
                            ( disabled ? "disabled" : "enabled" ),
                            ( cache_enabled ? "enabled" : "disabled" ) );
                    if ( rc == 0 )
                    {
                        if ( octx->options->detailed )
                        {
                            /* it is OK if we cannot find the root of a repository... */
                            char where[ 4096 ];
                            rc1 = KRepositoryRoot ( repo, where, sizeof where, NULL );
                            if ( rc1 == 0 )
                                rc = KOutMsg( ", at %s", where );
                            else
                            {
                                rc1 = KRepositoryResolver ( repo, where, sizeof where, NULL );
                                if ( rc1 == 0 )
                                    rc = KOutMsg( ", at %s", where );
                            }
                        }
                                            }
                    if ( rc == 0 )
                        rc = KOutMsg( "\n" );
                }
            }
        }
    }
    {
        rc1 = KRepositoryVectorWhack ( &repos );
        if ( rc1 != 0 )
        {
            PLOGERR( klogErr, ( klogErr, rc1,
                     "KRepositoryVectorWhack() for $(hint) failed in $(func)", "hint=%s,func=%s", hint, __func__ ) );
        }
    }
    return rc;
}
Beispiel #5
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;
}