Author: mlschroe Date: Thu Oct 30 15:22:58 2008 New Revision: 11551 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11551&view=rev Log: - add repodata_set_location() function - strip epoch in location functions - use repodata_set_location in parsers Modified: trunk/sat-solver/src/repodata.c trunk/sat-solver/src/repodata.h trunk/sat-solver/src/solvable.c trunk/sat-solver/tools/repo_rpmdb.c trunk/sat-solver/tools/repo_rpmmd.c trunk/sat-solver/tools/repo_susetags.c Modified: trunk/sat-solver/src/repodata.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/repodata.c?rev=11551&r1=11550&r2=11551&view=diff ============================================================================== --- trunk/sat-solver/src/repodata.c (original) +++ trunk/sat-solver/src/repodata.c Thu Oct 30 15:22:58 2008 @@ -1785,6 +1785,86 @@ 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) { Modified: trunk/sat-solver/src/repodata.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/repodata.h?rev=11551&r1=11550&r2=11551&view=diff ============================================================================== --- trunk/sat-solver/src/repodata.h (original) +++ trunk/sat-solver/src/repodata.h Thu Oct 30 15:22:58 2008 @@ -234,5 +234,6 @@ 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 */ Modified: trunk/sat-solver/src/solvable.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/solvable.c?rev=11551&r1=11550&r2=11551&view=diff ============================================================================== --- trunk/sat-solver/src/solvable.c (original) +++ trunk/sat-solver/src/solvable.c Thu Oct 30 15:22:58 2008 @@ -191,6 +191,17 @@ 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 @@ { 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); Modified: trunk/sat-solver/tools/repo_rpmdb.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/repo_rpmdb.c?rev=11551&r1=11550&r2=11551&view=diff ============================================================================== --- trunk/sat-solver/tools/repo_rpmdb.c (original) +++ trunk/sat-solver/tools/repo_rpmdb.c Thu Oct 30 15:22:58 2008 @@ -1545,62 +1545,6 @@ } -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 @@ 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); } Modified: trunk/sat-solver/tools/repo_rpmmd.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/repo_rpmmd.c?rev=11551&r1=11550&r2=11551&view=diff ============================================================================== --- trunk/sat-solver/tools/repo_rpmmd.c (original) +++ trunk/sat-solver/tools/repo_rpmmd.c Thu Oct 30 15:22:58 2008 @@ -773,19 +773,7 @@ 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); Modified: trunk/sat-solver/tools/repo_susetags.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/repo_susetags.c?rev=11551&r1=11550&r2=11551&view=diff ============================================================================== --- trunk/sat-solver/tools/repo_susetags.c (original) +++ trunk/sat-solver/tools/repo_susetags.c Thu Oct 30 15:22:58 2008 @@ -103,77 +103,6 @@ /* - * 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 @@ 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 @@ 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 @@ 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); -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org