/* DisplayName * get the repository display name, * if different from its actual name * * attempts to copy NUL-terminated name into provided buffer * * "buffer" [ OUT ] and "bsize" [ IN ] - name output parameter * * "name_size" [ OUT, NULL OKAY ] - returns the name size in * bytes, excluding any NUL termination. */ LIB_EXPORT rc_t CC KRepositoryDisplayName ( const KRepository *self, char *buffer, size_t bsize, size_t *name_size ) { rc_t rc; if ( self == NULL ) rc = RC ( rcKFG, rcNode, rcAccessing, rcSelf, rcNull ); else { const KConfigNode *node; if ( name_size != NULL ) * name_size = 0; rc = KConfigNodeOpenNodeRead ( self -> node, & node, "display-name" ); if ( rc != 0 ) rc = KRepositoryName ( self, buffer, bsize, name_size ); else { size_t num_read, remaining; rc = KConfigNodeRead ( node, 0, buffer, bsize, & num_read, & remaining ); KConfigNodeRelease ( node ); if ( rc == 0 ) { if ( name_size != NULL ) * name_size = num_read + remaining; if ( remaining != 0 ) rc = RC ( rcKFG, rcNode, rcAccessing, rcBuffer, rcInsufficient ); else if ( num_read < bsize ) buffer [ num_read ] = 0; } } } return rc; }
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; }