From: Michael Schroeder Date: Thu, 15 Sep 2022 14:11:38 +0000 (+0200) Subject: Implement getting the releasever from the base product on SUSE X-Git-Tag: 0.7.23~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de84237336b0214989010524c589f07371fc4f99;p=thirdparty%2Flibsolv.git Implement getting the releasever from the base product on SUSE --- diff --git a/examples/solv/repoinfo_config_yum.c b/examples/solv/repoinfo_config_yum.c index efccf1e8..9a36f9b5 100644 --- a/examples/solv/repoinfo_config_yum.c +++ b/examples/solv/repoinfo_config_yum.c @@ -21,6 +21,37 @@ # define REPOINFO_PATH "/etc/zypp/repos.d" #endif +static char * +find_releaseevr(Pool *pool) +{ +#ifdef SUSE + extern char *suse_find_baseproduct_evr(Pool *); +#endif + void *rpmstate; + char *releaseevr = 0; + Queue q; + +#ifdef SUSE + if ((releaseevr = suse_find_baseproduct_evr(pool)) != 0) + return releaseevr; +#endif + queue_init(&q); + rpmstate = rpm_state_create(pool, pool_get_rootdir(pool)); + rpm_installedrpmdbids(rpmstate, "Providename", "system-release", &q); + if (q.count) + { + void *handle; + char *p; + handle = rpm_byrpmdbid(rpmstate, q.elements[0]); + releaseevr = handle ? rpm_query(handle, SOLVABLE_EVR) : 0; + if (releaseevr && (p = strchr(releaseevr, '-')) != 0) + *p = 0; + } + rpm_state_free(rpmstate); + queue_free(&q); + return releaseevr; +} + char * yum_substitute(Pool *pool, char *line) { @@ -43,28 +74,15 @@ yum_substitute(Pool *pool, char *line) { if (!releaseevr) { - void *rpmstate; - Queue q; - - queue_init(&q); - rpmstate = rpm_state_create(pool, pool_get_rootdir(pool)); - rpm_installedrpmdbids(rpmstate, "Providename", "system-release", &q); - if (q.count) - { - void *handle; - char *p; - handle = rpm_byrpmdbid(rpmstate, q.elements[0]); - releaseevr = handle ? rpm_query(handle, SOLVABLE_EVR) : 0; - if (releaseevr && (p = strchr(releaseevr, '-')) != 0) - *p = 0; - } - rpm_state_free(rpmstate); - queue_free(&q); + releaseevr = find_releaseevr(pool); if (!releaseevr) { - fprintf(stderr, "no installed package provides 'system-release', cannot determine $releasever\n"); + fprintf(stderr, "Cannot determine $releasever\n"); exit(1); } + /* we only need the version */ + if ((p = strchr(releaseevr, '-')) != 0) + *p = 0; } *p2 = 0; p = pool_tmpjoin(pool, line, releaseevr, p2 + 11); diff --git a/examples/solv/repoinfo_system_rpm.c b/examples/solv/repoinfo_system_rpm.c index b556afc5..b5cfd8a2 100644 --- a/examples/solv/repoinfo_system_rpm.c +++ b/examples/solv/repoinfo_system_rpm.c @@ -161,4 +161,29 @@ commit_transactionelement_rpm(Pool *pool, Id type, Id p, FILE *fp) } } +#ifdef SUSE +char * +suse_find_baseproduct_evr(Pool *pool) +{ + char *evrstr = 0; + Pool *productspool = pool_create(); + Repo *productsrepo = repo_create(productspool, "products"); + Id p; + Solvable *s; + + pool_set_rootdir(productspool, pool_get_rootdir(pool)); + repo_add_products(productsrepo, PRODUCTS_PATH, REPO_USE_ROOTDIR); + FOR_REPO_SOLVABLES(productsrepo, p, s) + { + const char *type = solvable_lookup_str(s, PRODUCT_TYPE); + if (!type || strcmp(type, "base") != 0) + continue; + evrstr = solv_strdup(pool_id2str(productspool, s->evr)); + break; + } + pool_free(productspool); + return evrstr; +} +#endif + #endif