From: Michael Schroeder Date: Thu, 30 Oct 2008 14:22:58 +0000 (+0000) Subject: - add repodata_set_location() function X-Git-Tag: BASE-SuSE-Code-12_1-Branch~308^2~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae568eff26e1749b016eea38c839f26e2da6e25c;p=thirdparty%2Flibsolv.git - add repodata_set_location() function - strip epoch in location functions - use repodata_set_location in parsers --- diff --git a/src/repodata.c b/src/repodata.c index d3b9b4a0..4991e458 100644 --- a/src/repodata.c +++ b/src/repodata.c @@ -1785,6 +1785,86 @@ repodata_chk2str(Repodata *data, Id type, const unsigned char *buf) return str; } +static inline const char * +evrid2vrstr(Pool *pool, Id evrid) +{ + const char *p, *evr = id2str(pool, evrid); + if (!evr) + return evr; + for (p = evr; *p >= '0' && *p <= '9'; p++) + ; + return p != evr && *p == ':' ? p + 1 : evr; +} + +void +repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, const char *file) +{ + Pool *pool = data->repo->pool; + Solvable *s; + const char *str, *fp; + int l = 0; + + if (medianr) + repodata_set_constant(data, solvid, SOLVABLE_MEDIANR, medianr); + if (!dir) + { + if ((dir = strrchr(file, '/')) != 0) + { + l = dir - file; + dir = file; + file = dir + l + 1; + if (!l) + l++; + } + } + else + l = strlen(dir); + if (l >= 2 && dir[0] == '.' && dir[1] == '/' && (l == 2 || dir[2] != '/')) + { + dir += 2; + l -= 2; + } + if (l == 1 && dir[0] == '.') + l = 0; + s = pool->solvables + solvid; + if (dir && l) + { + str = id2str(pool, s->arch); + if (!strncmp(dir, str, l) && !str[l]) + repodata_set_void(data, solvid, SOLVABLE_MEDIADIR); + else if (!dir[l]) + repodata_set_str(data, solvid, SOLVABLE_MEDIADIR, dir); + else + { + char *dir2 = strdup(dir); + dir2[l] = 0; + repodata_set_str(data, solvid, SOLVABLE_MEDIADIR, dir2); + free(dir2); + } + } + fp = file; + str = id2str(pool, s->name); + l = strlen(str); + if ((!l || !strncmp(fp, str, l)) && fp[l] == '-') + { + fp += l + 1; + str = evrid2vrstr(pool, s->evr); + l = strlen(str); + if ((!l || !strncmp(fp, str, l)) && fp[l] == '.') + { + fp += l + 1; + str = id2str(pool, s->arch); + l = strlen(str); + if ((!l || !strncmp(fp, str, l)) && !strcmp(fp + l, ".rpm")) + { + repodata_set_void(data, solvid, SOLVABLE_MEDIAFILE); + return; + } + } + } + repodata_set_str(data, solvid, SOLVABLE_MEDIAFILE, file); +} + Id repodata_globalize_id(Repodata *data, Id id) { diff --git a/src/repodata.h b/src/repodata.h index 9cce3123..e425482f 100644 --- a/src/repodata.h +++ b/src/repodata.h @@ -234,5 +234,6 @@ Id repodata_globalize_id(Repodata *data, Id id); Id repodata_str2dir(Repodata *data, const char *dir, int create); const char *repodata_dir2str(Repodata *data, Id did, const char *suf); const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf); +void repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, const char *file); #endif /* SATSOLVER_REPODATA_H */ diff --git a/src/solvable.c b/src/solvable.c index 70214a9b..0174ee50 100644 --- a/src/solvable.c +++ b/src/solvable.c @@ -191,6 +191,17 @@ solvable_lookup_checksum(Solvable *s, Id keyname, Id *typep) return chk ? repodata_chk2str(s->repo->repodata, *typep, chk) : 0; } +static inline const char * +evrid2vrstr(Pool *pool, Id evrid) +{ + const char *p, *evr = id2str(pool, evrid); + if (!evr) + return evr; + for (p = evr; *p >= '0' && *p <= '9'; p++) + ; + return p != evr && *p == ':' ? p + 1 : evr; +} + char * solvable_get_location(Solvable *s, unsigned int *medianrp) { @@ -214,9 +225,9 @@ solvable_get_location(Solvable *s, unsigned int *medianrp) { const char *name, *evr, *arch; name = id2str(pool, s->name); - evr = id2str(pool, s->evr); + evr = evrid2vrstr(pool, s->evr); arch = id2str(pool, s->arch); - /* name-evr.arch.rpm */ + /* name-vr.arch.rpm */ loc = pool_alloctmpspace(pool, l + strlen(name) + strlen(evr) + strlen(arch) + 7); if (mediadir) sprintf(loc, "%s/%s-%s.%s.rpm", mediadir, name, evr, arch); diff --git a/tools/repo_rpmdb.c b/tools/repo_rpmdb.c index e7818f79..a19d5d16 100644 --- a/tools/repo_rpmdb.c +++ b/tools/repo_rpmdb.c @@ -1545,62 +1545,6 @@ getu32(unsigned char *dp) } -static void -add_location(Repodata *data, Solvable *s, Id handle, const char *location) -{ - Pool *pool = s->repo->pool; - const char *name, *n1, *n2; - int l; - - /* skip ./ prefix */ - if (location[0] == '.' && location[1] == '/' && location[2] != '/') - location += 2; - - name = strrchr(location, '/'); - if (!name) - name = location; - else - { - name++; - n2 = id2str(pool, s->arch); - l = strlen(n2); - if (strncmp(location, n2, l) != 0 || location + l + 1 != name) - { - /* too bad, need to store directory */ - char *dir = strdup(location); - dir[name - location - 1] = 0; - repodata_set_str(data, handle, SOLVABLE_MEDIADIR, dir); - free(dir); - } - else - repodata_set_void(data, handle, SOLVABLE_MEDIADIR); - } - n1 = name; - for (n2 = id2str(pool, s->name); *n2; n1++, n2++) - if (*n1 != *n2) - break; - if (*n2 || *n1 != '-') - goto nontrivial; - n1++; - for (n2 = id2str (pool, s->evr); *n2; n1++, n2++) - if (*n1 != *n2) - break; - if (*n2 || *n1 != '.') - goto nontrivial; - n1++; - for (n2 = id2str (pool, s->arch); *n2; n1++, n2++) - if (*n1 != *n2) - break; - if (*n2 || strcmp (n1, ".rpm")) - goto nontrivial; - repodata_set_void(data, handle, SOLVABLE_MEDIAFILE); - return; - -nontrivial: - repodata_set_str(data, handle, SOLVABLE_MEDIAFILE, name); - return; -} - void repo_add_rpms(Repo *repo, const char **rpms, int nrpms, int flags) { @@ -1728,7 +1672,7 @@ repo_add_rpms(Repo *repo, const char **rpms, int nrpms, int flags) if (data) { Id handle = s - pool->solvables; - add_location(data, s, handle, rpms[i]); + repodata_set_location(data, handle, 0, 0, rpms[i]); repodata_set_num(data, handle, SOLVABLE_DOWNLOADSIZE, (unsigned int)((stb.st_size + 1023) / 1024)); repodata_set_num(data, handle, SOLVABLE_HEADEREND, headerend); } diff --git a/tools/repo_rpmmd.c b/tools/repo_rpmmd.c index 4fdb45f0..e0378c5c 100644 --- a/tools/repo_rpmmd.c +++ b/tools/repo_rpmmd.c @@ -773,19 +773,7 @@ startElement(void *userData, const char *name, const char **atts) case STATE_LOCATION: str = find_attr("href", atts); if (str) - { - const char *str2 = strrchr(str, '/'); - if (str2) - { - char *str3 = strdup(str); - str3[str2 - str] = 0; - repodata_set_poolstr(pd->data, handle, SOLVABLE_MEDIADIR, str3); - free(str3); - repodata_set_str(pd->data, handle, SOLVABLE_MEDIAFILE, str2 + 1); - } - else - repodata_set_str(pd->data, handle, SOLVABLE_MEDIAFILE, str); - } + repodata_set_location(pd->data, handle, 0, 0, str); break; case STATE_CHECKSUM: pd->tmpattr = find_attr("type", atts); diff --git a/tools/repo_susetags.c b/tools/repo_susetags.c index d5e2dfb3..5a2b50df 100644 --- a/tools/repo_susetags.c +++ b/tools/repo_susetags.c @@ -102,77 +102,6 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, Id ma } -/* - * add_location - * - */ - -static void -add_location(struct parsedata *pd, char *line, Solvable *s, Id handle) -{ - Pool *pool = s->repo->pool; - char *sp[3]; - int i; - - i = split(line, sp, 3); - if (i != 2 && i != 3) - { - pool_debug(pool, SAT_FATAL, "susetags: bad location line: %d: %s\n", pd->lineno, line); - exit(1); - } - /* If we have a dirname, let's see if it's the same as arch. In that - case don't store it. */ - if (i == 3 && !strcmp (sp[2], id2str (pool, s->arch))) - sp[2] = 0, i = 2; - if (i == 3 && sp[2]) - { - /* medianr filename dir - don't optimize this one */ - repodata_set_constant(pd->data, handle, SOLVABLE_MEDIANR, atoi(sp[0])); - repodata_set_poolstr(pd->data, handle, SOLVABLE_MEDIADIR, sp[2]); - repodata_set_str(pd->data, handle, SOLVABLE_MEDIAFILE, sp[1]); - return; - } - else - { - /* Let's see if we can optimize this a bit. If the media file name - can be formed by the base rpm information we don't store it, but - only a flag that we've seen it. */ - unsigned int medianr = atoi (sp[0]); - const char *n1 = sp[1]; - const char *n2 = id2str (pool, s->name); - for (n2 = id2str (pool, s->name); *n2; n1++, n2++) - if (*n1 != *n2) - break; - if (*n2 || *n1 != '-') - goto nontrivial; - - n1++; - for (n2 = id2str (pool, s->evr); *n2; n1++, n2++) - if (*n1 != *n2) - break; - if (*n2 || *n1 != '.') - goto nontrivial; - n1++; - for (n2 = id2str (pool, s->arch); *n2; n1++, n2++) - if (*n1 != *n2) - break; - if (*n2 || strcmp (n1, ".rpm")) - goto nontrivial; - - repodata_set_constant(pd->data, handle, SOLVABLE_MEDIANR, medianr); - repodata_set_void(pd->data, handle, SOLVABLE_MEDIADIR); - repodata_set_void(pd->data, handle, SOLVABLE_MEDIAFILE); - return; - -nontrivial: - repodata_set_constant(pd->data, handle, SOLVABLE_MEDIANR, medianr); - repodata_set_void(pd->data, handle, SOLVABLE_MEDIADIR); - repodata_set_str(pd->data, handle, SOLVABLE_MEDIAFILE, sp[1]); - return; - } -} - /* * add_source * @@ -329,8 +258,8 @@ commit_diskusage (struct parsedata *pd, Id handle) unsigned slen = sizeof (sbuf); for (i = 0; i < pd->ndirs; i++) { - dir2str (attr, pd->dirs[i][0], &buf, &slen); - fprintf (stderr, "have dir %d %d %d %s\n", pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2], buf); + dir2str(attr, pd->dirs[i][0], &buf, &slen); + fprintf(stderr, "have dir %d %d %d %s\n", pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2], buf); } if (buf != sbuf) free (buf); @@ -736,7 +665,7 @@ repo_add_susetags(Repo *repo, FILE *fp, Id product, const char *language, int fl solvables. */ if (indesc >= 2 && !s) { - fprintf (stderr, "Huh %d: %s?\n", pd.lineno, line); + pool_debug(pool, SAT_ERROR, "susetags: huh %d: %s?\n", pd.lineno, line); continue; } switch (tag) @@ -838,13 +767,21 @@ repo_add_susetags(Repo *repo, FILE *fp, Id product, const char *language, int fl repodata_set_poolstr(data, handle, SOLVABLE_LICENSE, line + 6); continue; case CTAG('=', 'L', 'o', 'c'): - add_location(&pd, line + 6, s, handle); + { + int i = split(line + 6, sp, 3); + if (i != 2 && i != 3) + { + pool_debug(pool, SAT_FATAL, "susetags: bad location line: %d: %s\n", pd.lineno, line); + exit(1); + } + repodata_set_location(data, handle, atoi(sp[0]), i == 3 ? sp[2] : id2str(pool, s->arch), sp[1]); + } continue; case CTAG('=', 'S', 'r', 'c'): add_source(&pd, line + 6, s, handle); continue; case CTAG('=', 'S', 'i', 'z'): - if (split (line + 6, sp, 3) == 2) + if (split(line + 6, sp, 3) == 2) { repodata_set_num(data, handle, SOLVABLE_DOWNLOADSIZE, (unsigned int)(atoi(sp[0]) + 1023) / 1024); repodata_set_num(data, handle, SOLVABLE_INSTALLSIZE, (unsigned int)(atoi(sp[1]) + 1023) / 1024);