void repo_set_id(Repo *repo, Id p, Id keyname, Id id) { Repodata *data; if (p >= 0) { switch (keyname) { case SOLVABLE_NAME: repo->pool->solvables[p].name = id; return; case SOLVABLE_ARCH: repo->pool->solvables[p].arch = id; return; case SOLVABLE_EVR: repo->pool->solvables[p].evr = id; return; case SOLVABLE_VENDOR: repo->pool->solvables[p].vendor = id; return; } } data = repo_last_repodata(repo); if (data->localpool) id = repodata_localize_id(data, id, 1); repodata_set_id(data, p, keyname, id); }
int repo_add_products(Repo *repo, const char *proddir, int flags) { const char *fullpath; DIR *dir; if (proddir) { dir = opendir(flags & REPO_USE_ROOTDIR ? pool_prepend_rootdir_tmp(repo->pool, proddir) : proddir); if (dir) { /* assume code11 stype products */ closedir(dir); return repo_add_code11_products(repo, proddir, flags); } } /* code11 didn't work, try old code10 zyppdb */ fullpath = "/var/lib/zypp/db/products"; if (flags & REPO_USE_ROOTDIR) fullpath = pool_prepend_rootdir_tmp(repo->pool, fullpath); dir = opendir(fullpath); if (dir) { closedir(dir); /* assume code10 style products */ return repo_add_zyppdb_products(repo, "/var/lib/zypp/db/products", flags); } /* code10/11 didn't work, try -release files parsing */ fullpath = "/etc"; if (flags & REPO_USE_ROOTDIR) fullpath = pool_prepend_rootdir_tmp(repo->pool, fullpath); dir = opendir(fullpath); if (dir) { closedir(dir); return repo_add_releasefile_products(repo, "/etc", flags); } /* no luck. check if the rootdir exists */ fullpath = pool_get_rootdir(repo->pool); if (fullpath && *fullpath) { dir = opendir(fullpath); if (!dir) return pool_error(repo->pool, -1, "%s: %s", fullpath, strerror(errno)); closedir(dir); } /* the least we can do... */ if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0) repodata_internalize(repo_last_repodata(repo)); return 0; }
int repo_add_releasefile_products(Repo *repo, const char *dirpath, int flags) { DIR *dir; struct dirent *entry; FILE *fp; char *fullpath; struct parsedata pd; if (!dirpath) dirpath = "/etc"; if (flags & REPO_USE_ROOTDIR) dirpath = pool_prepend_rootdir(repo->pool, dirpath); dir = opendir(dirpath); if (!dir) { if (flags & REPO_USE_ROOTDIR) solv_free((char *)dirpath); return 0; } memset(&pd, 0, sizeof(pd)); pd.repo = repo; while ((entry = readdir(dir))) { int len = strlen(entry->d_name); if (len > 8 && !strcmp(entry->d_name + len - 8, "-release")) { /* skip /etc/lsb-release, thats not a product per-se */ if (strcmp(entry->d_name, "lsb-release") == 0) continue; fullpath = join2(&pd.jd, dirpath, "/", entry->d_name); if ((fp = fopen(fullpath, "r")) == 0) { pool_error(repo->pool, 0, "%s: %s", fullpath, strerror(errno)); continue; } add_releasefile_product(&pd, fp); fclose(fp); } } closedir(dir); join_freemem(&pd.jd); if (flags & REPO_USE_ROOTDIR) solv_free((char *)dirpath); if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0) repodata_internalize(repo_last_repodata(repo)); return 0; }
void repo_set_num(Repo *repo, Id p, Id keyname, unsigned int num) { Repodata *data; if (p >= 0) { if (keyname == RPM_RPMDBID) { if (!repo->rpmdbid) repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id)); repo->rpmdbid[p] = num; return; } } data = repo_last_repodata(repo); repodata_set_num(data, p, keyname, num); }
void repo_add_products(Repo *repo, const char *proddir, const char *root, int flags) { const char *fullpath; DIR *dir; dir = opendir(proddir); if (dir) { /* assume code11 stype products */ closedir(dir); repo_add_code11_products(repo, proddir, flags); return; } /* code11 didn't work, try old zyppdb */ fullpath = root ? join2(root, "", "/var/lib/zypp/db/products") : "/var/lib/zypp/db/products"; dir = opendir(fullpath); if (dir) { closedir(dir); /* assume code10 style products */ repo_add_zyppdb_products(repo, fullpath, flags); join_freemem(); return; } /* code11 didn't work, try -release files parsing */ fullpath = root ? join2(root, "", "/etc") : "/etc"; dir = opendir(fullpath); if (dir) { closedir(dir); repo_add_releasefile_products(repo, fullpath, flags); join_freemem(); return; } /* no luck. print an error message in case the root argument is wrong */ perror(fullpath); join_freemem(); /* the least we can do... */ if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0) repodata_internalize(repo_last_repodata(repo)); }
void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str) { Repodata *data; if (p >= 0) { switch (keyname) { case SOLVABLE_NAME: case SOLVABLE_ARCH: case SOLVABLE_EVR: case SOLVABLE_VENDOR: repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1)); return; } } data = repo_last_repodata(repo); repodata_set_poolstr(data, p, keyname, str); }
void repo_add_deparray(Repo *repo, Id p, Id keyname, Id dep, Id marker) { Repodata *data; if (p >= 0) { Solvable *s = repo->pool->solvables + p; switch (keyname) { case SOLVABLE_PROVIDES: s->provides = repo_addid_dep(repo, s->provides, dep, marker); return; case SOLVABLE_OBSOLETES: s->obsoletes = repo_addid_dep(repo, s->obsoletes, dep, marker); return; case SOLVABLE_CONFLICTS: s->conflicts = repo_addid_dep(repo, s->conflicts, dep, marker); return; case SOLVABLE_REQUIRES: s->requires = repo_addid_dep(repo, s->requires, dep, marker); return; case SOLVABLE_RECOMMENDS: s->recommends = repo_addid_dep(repo, s->recommends, dep, marker); return; case SOLVABLE_SUGGESTS: s->suggests = repo_addid_dep(repo, s->suggests, dep, marker); return; case SOLVABLE_SUPPLEMENTS: s->supplements = repo_addid_dep(repo, s->supplements, dep, marker); return; case SOLVABLE_ENHANCES: s->enhances = repo_addid_dep(repo, s->enhances, dep, marker); return; } } data = repo_last_repodata(repo); repodata_add_idarray(data, p, keyname, dep); }
int repo_add_releasefile_products(Repo *repo, const char *dirpath, int flags) { DIR *dir; struct dirent *entry; FILE *fp; char *fullpath; dir = opendir(dirpath); if (!dir) return 0; while ((entry = readdir(dir))) { int len = strlen(entry->d_name); if (len > 8 && !strcmp(entry->d_name + len - 8, "-release")) { /* skip /etc/lsb-release, thats not a product per-se */ if (strcmp(entry->d_name, "lsb-release") == 0) continue; fullpath = join2(dirpath, "/", entry->d_name); if ((fp = fopen(fullpath, "r")) == 0) { perror(fullpath); continue; } add_releasefile_product(repo, fp); fclose(fp); } } closedir(dir); join_freemem(); if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0) repodata_internalize(repo_last_repodata(repo)); return 0; }
int susetags_load(struct repoinfo *cinfo, Pool **sigpoolp) { Repo *repo = cinfo->repo; Pool *pool = repo->pool; Repodata *data; const char *filename; const unsigned char *filechksum; Id filechksumtype; FILE *fp; const char *descrdir; int defvendor; printf("susetags repo '%s':", cinfo->alias); fflush(stdout); descrdir = 0; defvendor = 0; if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0) { printf(" no content file\n"); cinfo->incomplete = 1; return 0; } calc_cookie_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie); cinfo->cookieset = 1; if (usecachedrepo(cinfo, 0, 1)) { printf(" cached\n"); fclose(fp); return 1; } if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "content.asc", sigpoolp)) { fclose(fp); cinfo->incomplete = 1; return 0; } if (repo_add_content(repo, fp, 0)) { printf("content: %s\n", pool_errstr(pool)); fclose(fp); cinfo->incomplete = 1; return 0; } fclose(fp); defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR); descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR); if (!descrdir) descrdir = "suse/setup/descr"; filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype); if (!filename) filename = susetags_find(repo, "packages", &filechksum, &filechksumtype); if (!filename) { printf(" no packages file entry, skipped\n"); cinfo->incomplete = 1; return 0; } printf(" fetching\n"); if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) == 0) { cinfo->incomplete = 1; return 0; /* hopeless */ } if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES)) { printf("packages: %s\n", pool_errstr(pool)); fclose(fp); cinfo->incomplete = 1; return 0; /* hopeless */ } fclose(fp); /* add default language */ filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype); if (!filename) filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype); if (filename) { if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) != 0) { if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES)) { printf("packages.en: %s\n", pool_errstr(pool)); cinfo->incomplete = 1; } fclose(fp); } } filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype); if (filename) { if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) != 0) { char pbuf[256]; while (fgets(pbuf, sizeof(pbuf), fp)) { int l = strlen(pbuf); FILE *fp2; if (l && pbuf[l - 1] == '\n') pbuf[--l] = 0; if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0) continue; filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype); if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) != 0) { if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE)) { printf("%s: %s\n", pbuf, pool_errstr(pool)); cinfo->incomplete = 1; } fclose(fp2); } } fclose(fp); } } #ifdef ENABLE_APPDATA filename = susetags_find(repo, "appdata.xml.gz", &filechksum, &filechksumtype); if (!filename) filename = susetags_find(repo, "appdata.xml", &filechksum, &filechksumtype); if (filename && (fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) != 0) { if (repo_add_appdata(repo, fp, 0)) { printf("appdata: %s\n", pool_errstr(pool)); cinfo->incomplete = 1; } fclose(fp); } #endif repo_internalize(repo); #ifdef SUSE repo_add_autopattern(repo, 0); #endif data = repo_add_repodata(repo, 0); repodata_extend_block(data, repo->start, repo->end - repo->start); susetags_add_ext(repo, data); repodata_internalize(data); writecachedrepo(cinfo, 0, 0); repodata_create_stubs(repo_last_repodata(repo)); return 1; }
void repo_set_deparray(Repo *repo, Id p, Id keyname, Queue *q, Id marker) { Repodata *data; if (marker) { /* complex case, splice old and new arrays */ int i; Queue q2; queue_init(&q2); repo_lookup_deparray(repo, p, keyname, &q2, -marker); if (marker > 0) { if (q->count) { queue_push(&q2, marker); for (i = 0; i < q->count; i++) queue_push(&q2, q->elements[i]); } } else { if (q2.count) queue_insert(&q2, 0, -marker); queue_insertn(&q2, 0, q->count); for (i = 0; i < q->count; i++) q2.elements[i] = q->elements[i]; } repo_set_deparray(repo, p, keyname, &q2, 0); queue_free(&q2); return; } if (p >= 0) { Solvable *s = repo->pool->solvables + p; switch (keyname) { case SOLVABLE_PROVIDES: s->provides = repo_set_idarray_solvable(repo, q); return; case SOLVABLE_OBSOLETES: s->obsoletes = repo_set_idarray_solvable(repo, q); return; case SOLVABLE_CONFLICTS: s->conflicts = repo_set_idarray_solvable(repo, q); return; case SOLVABLE_REQUIRES: s->requires = repo_set_idarray_solvable(repo, q); return; case SOLVABLE_RECOMMENDS: s->recommends = repo_set_idarray_solvable(repo, q); return; case SOLVABLE_SUGGESTS: s->suggests = repo_set_idarray_solvable(repo, q); return; case SOLVABLE_SUPPLEMENTS: s->supplements = repo_set_idarray_solvable(repo, q); return; case SOLVABLE_ENHANCES: s->enhances = repo_set_idarray_solvable(repo, q); return; } } data = repo_last_repodata(repo); repodata_set_idarray(data, p, keyname, q); }
void repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str) { Repodata *data = repo_last_repodata(repo); repodata_add_poolstr_array(data, p, keyname, str); }