From: Michael Schroeder Date: Tue, 6 Nov 2012 12:47:27 +0000 (+0100) Subject: add repodata_set_deltalocation and use it in the parsers X-Git-Tag: BASE-SuSE-Code-12_3-Branch~185 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b272a2e7df10744df1b7224b1abebeba64f88d6;p=thirdparty%2Flibsolv.git add repodata_set_deltalocation and use it in the parsers --- diff --git a/ext/repo_deltainfoxml.c b/ext/repo_deltainfoxml.c index c841f5ed..6b1113f6 100644 --- a/ext/repo_deltainfoxml.c +++ b/ext/repo_deltainfoxml.c @@ -77,10 +77,7 @@ static struct stateswitch stateswitches[] = { /* Cumulated info about the current deltarpm or patchrpm */ struct deltarpm { - Id locdir; - Id locname; - Id locevr; - Id locsuffix; + char *location; unsigned int buildtime; unsigned long long downloadsize; char *filechecksum; @@ -208,68 +205,6 @@ makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts) return pool_str2id(pool, pd->content, 1); } -static void -parse_delta_location(struct parsedata *pd, const char* str) -{ - Pool *pool = pd->pool; - if (str) - { - /* Separate the filename into its different parts. - rpm/x86_64/alsa-1.0.14-31_31.2.x86_64.delta.rpm - --> dir = rpm/x86_64 - name = alsa - evr = 1.0.14-31_31.2 - suffix = x86_64.delta.rpm. */ - char *real_str = solv_strdup(str); - char *s = real_str; - char *s1, *s2; - s1 = strrchr (s, '/'); - if (s1) - { - pd->delta.locdir = pool_strn2id(pool, s, s1 - s, 1); - s = s1 + 1; - } - /* Guess suffix. */ - s1 = strrchr (s, '.'); - if (s1) - { - for (s2 = s1 - 1; s2 > s; s2--) - if (*s2 == '.') - break; - if (!strcmp (s2, ".delta.rpm") || !strcmp (s2, ".patch.rpm")) - { - s1 = s2; - /* We accept one more item as suffix. */ - for (s2 = s1 - 1; s2 > s; s2--) - if (*s2 == '.') - break; - s1 = s2; - } - if (*s1 == '.') - *s1++ = 0; - pd->delta.locsuffix = pool_str2id(pool, s1, 1); - } - /* Last '-'. */ - s1 = strrchr (s, '-'); - if (s1) - { - /* Second to last '-'. */ - for (s2 = s1 - 1; s2 > s; s2--) - if (*s2 == '-') - break; - } - else - s2 = 0; - if (s2 > s && *s2 == '-') - { - *s2++ = 0; - pd->delta.locevr = pool_str2id(pool, s2, 1); - } - pd->delta.locname = pool_str2id(pool, s, 1); - free(real_str); - } -} - static void XMLCALL startElement(void *userData, const char *name, const char **atts) { @@ -326,7 +261,7 @@ startElement(void *userData, const char *name, const char **atts) case STATE_FILENAME: break; case STATE_LOCATION: - parse_delta_location(pd, find_attr("href", atts)); + pd->delta.location = solv_strdup(find_attr("href", atts)); break; case STATE_SIZE: break; @@ -389,10 +324,8 @@ endElement(void *userData, const char *name) repodata_set_id(pd->data, handle, DELTA_PACKAGE_NAME, pd->newpkgname); repodata_set_id(pd->data, handle, DELTA_PACKAGE_EVR, pd->newpkgevr); repodata_set_id(pd->data, handle, DELTA_PACKAGE_ARCH, pd->newpkgarch); - repodata_set_id(pd->data, handle, DELTA_LOCATION_NAME, d->locname); - repodata_set_id(pd->data, handle, DELTA_LOCATION_DIR, d->locdir); - repodata_set_id(pd->data, handle, DELTA_LOCATION_EVR, d->locevr); - repodata_set_id(pd->data, handle, DELTA_LOCATION_SUFFIX, d->locsuffix); + if (d->location) + repodata_set_deltalocation(pd->data, handle, 0, 0, d->location); if (d->downloadsize) repodata_set_num(pd->data, handle, DELTA_DOWNLOADSIZE, d->downloadsize); if (d->filechecksum) @@ -410,9 +343,10 @@ endElement(void *userData, const char *name) pd->delta.bevr = solv_free(pd->delta.bevr); pd->delta.nbevr = 0; pd->delta.seqnum = solv_free(pd->delta.seqnum); + pd->delta.location = solv_free(pd->delta.location); break; case STATE_FILENAME: - parse_delta_location(pd, pd->content); + pd->delta.location = solv_strdup(pd->content); break; case STATE_CHECKSUM: pd->delta.filechecksum = solv_strdup(pd->content); diff --git a/ext/repo_susetags.c b/ext/repo_susetags.c index 8edce444..dcc7e888 100644 --- a/ext/repo_susetags.c +++ b/ext/repo_susetags.c @@ -223,67 +223,6 @@ set_checksum(struct parsedata *pd, Repodata *data, Id handle, Id keyname, char * repodata_set_checksum(data, handle, keyname, type, sp[1]); } -static void -set_delta_location(Repodata *data, Id handle, int medianr, char *dir, char *file) -{ - Pool *pool = data->repo->pool; - int l = 0; - char *p, *op; - - 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; - if (dir && l) - repodata_set_id(data, handle, DELTA_LOCATION_DIR, pool_strn2id(pool, dir, l, 1)); - if ((p = strrchr(file, '.')) != 0) - { - *p = 0; - if ((op = strrchr(file, '.')) != 0) - { - *p = '.'; - p = op; - *p = 0; - if (!strcmp(p + 1, "delta.rpm") && (op = strrchr(file, '.')) != 0) - { - *p = '.'; - p = op; - *p = 0; - } - } - repodata_set_id(data, handle, DELTA_LOCATION_SUFFIX, pool_str2id(pool, p + 1, 1)); - } - if ((p = strrchr(file, '-')) != 0) - { - *p = 0; - if ((op = strrchr(file, '-')) != 0) - { - *p = '-'; - p = op; - *p = 0; - } - repodata_set_id(data, handle, DELTA_LOCATION_EVR, pool_str2id(pool, p + 1, 1)); - } - repodata_set_id(data, handle, DELTA_LOCATION_NAME, pool_str2id(pool, file, 1)); -} - - /* * id3_cmp @@ -755,7 +694,7 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int pd.ret = pool_error(pool, -1, "susetags: line %d: bad location line '%s'\n", pd.lineno, line); continue; } - set_delta_location(data, handle, atoi(sp[0]), i == 3 ? sp[2] : 0, sp[1]); + repodata_set_deltalocation(data, handle, atoi(sp[0]), i == 3 ? sp[2] : 0, sp[1]); continue; } case CTAG('=', 'S', 'i', 'z'): diff --git a/src/libsolv.ver b/src/libsolv.ver index b19792ff..f8d8b018 100644 --- a/src/libsolv.ver +++ b/src/libsolv.ver @@ -209,6 +209,7 @@ SOLV_1.0 { repodata_set_constantid; repodata_set_deleted; repodata_set_deleted_uninternalized; + repodata_set_deltalocation; repodata_set_id; repodata_set_idarray; repodata_set_location; diff --git a/src/repodata.c b/src/repodata.c index e91fffb8..a812ba84 100644 --- a/src/repodata.c +++ b/src/repodata.c @@ -2304,6 +2304,86 @@ repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, c repodata_set_str(data, solvid, SOLVABLE_MEDIAFILE, file); } +static inline void repodata_set_poolstrn(Repodata *data, Id solvid, Id keyname, const char *str, int l) +{ + Id id; + if (data->localpool) + id = stringpool_strn2id(&data->spool, str, l, 1); + else + id = pool_strn2id(data->repo->pool, str, l, 1); + repodata_set_id(data, solvid, keyname, id); +} + +/* XXX: medianr is currently not stored */ +void +repodata_set_deltalocation(Repodata *data, Id handle, int medianr, const char *dir, const char *file) +{ + int l = 0; + const char *evr, *suf, *s; + + 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; + if (dir && l) + repodata_set_poolstrn(data, handle, DELTA_LOCATION_DIR, dir, l); + evr = strchr(file, '-'); + if (evr) + { + for (s = evr - 1; s > file; s--) + if (*s == '-') + { + evr = s; + break; + } + } + suf = strrchr(file, '.'); + if (suf) + { + for (s = suf - 1; s > file; s--) + if (*s == '.') + { + suf = s; + break; + } + if (!strcmp(suf, ".delta.rpm") || !strcmp(suf, ".patch.rpm")) + { + /* We accept one more item as suffix. */ + for (s = suf - 1; s > file; s--) + if (*s == '.') + { + suf = s; + break; + } + } + } + if (!evr) + suf = 0; + if (suf && evr && suf < evr) + suf = 0; + repodata_set_poolstrn(data, handle, DELTA_LOCATION_NAME, file, evr ? evr - file : strlen(file)); + if (evr) + repodata_set_poolstrn(data, handle, DELTA_LOCATION_EVR, evr + 1, suf ? suf - evr - 1: strlen(evr + 1)); + if (suf) + repodata_set_poolstr(data, handle, DELTA_LOCATION_SUFFIX, suf + 1); +} + void repodata_set_sourcepkg(Repodata *data, Id solvid, const char *sourcepkg) { diff --git a/src/repodata.h b/src/repodata.h index 8e9e2711..3951dddb 100644 --- a/src/repodata.h +++ b/src/repodata.h @@ -288,6 +288,7 @@ 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); +void repodata_set_deltalocation(Repodata *data, Id handle, int medianr, const char *dir, const char *file); void repodata_set_sourcepkg(Repodata *data, Id solvid, const char *sourcepkg); Id repodata_lookup_id_uninternalized(Repodata *data, Id solvid, Id keyname, Id voidid);