diff options
author | Dan McGee <dan@archlinux.org> | 2011-08-09 08:00:16 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-08-15 19:56:41 +0200 |
commit | a628feee46f2200db7d3303091813f050a61d0a3 (patch) | |
tree | 47e9924d205098c48a6ef3db33e4424b9845c0fc /lib/libalpm/be_local.c | |
parent | bd5ec9cd8e23bba4334a7b3a5a73843c3667c085 (diff) | |
download | pacman-a628feee46f2200db7d3303091813f050a61d0a3.tar.gz pacman-a628feee46f2200db7d3303091813f050a61d0a3.tar.xz |
Parse conflicts/provides/replaces at database load time
We did this with depends way back in commit c244cfecf654d3 in 2007. We
can do it with these fields as well.
Of note is the inclusion of provides even though only '=' is supported-
we'll parse other things, but no guarantees are given as to behavior,
which is more or less similar to before since we only looked for the
equals sign.
Also of note is the non-inclusion of optdepends; this will likely be
resolved down the road.
The biggest benefactors of this change will be the resolving code that
formerly had to parse and reparse several of these fields; it only
happens once now at load time. This does lead to the disadvantage that
we will now always be parsing this information up front even if we never
need it in the split form, but as these are uncommon fields and our
parser is quite efficient it shouldn't be a big concern.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/be_local.c')
-rw-r--r-- | lib/libalpm/be_local.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index fdb4ceaf..a874504e 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -509,6 +509,12 @@ static char *get_pkgpath(alpm_db_t *db, alpm_pkg_t *info) f = alpm_list_add(f, linedup); \ } while(1) /* note the while(1) and not (0) */ +#define READ_AND_SPLITDEP(f) do { \ + if(fgets(line, sizeof(line), fp) == NULL && !feof(fp)) goto error; \ + if(_alpm_strip_newline(line) == 0) break; \ + f = alpm_list_add(f, _alpm_splitdep(line)); \ +} while(1) /* note the while(1) and not (0) */ + static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq) { FILE *fp = NULL; @@ -601,20 +607,15 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq) /* also store this value to isize */ info->isize = info->size; } else if(strcmp(line, "%REPLACES%") == 0) { - READ_AND_STORE_ALL(info->replaces); + READ_AND_SPLITDEP(info->replaces); } else if(strcmp(line, "%DEPENDS%") == 0) { - /* Different than the rest because of the _alpm_splitdep call. */ - while(1) { - READ_NEXT(); - if(strlen(line) == 0) break; - info->depends = alpm_list_add(info->depends, _alpm_splitdep(line)); - } + READ_AND_SPLITDEP(info->depends); } else if(strcmp(line, "%OPTDEPENDS%") == 0) { READ_AND_STORE_ALL(info->optdepends); } else if(strcmp(line, "%CONFLICTS%") == 0) { - READ_AND_STORE_ALL(info->conflicts); + READ_AND_SPLITDEP(info->conflicts); } else if(strcmp(line, "%PROVIDES%") == 0) { - READ_AND_STORE_ALL(info->provides); + READ_AND_SPLITDEP(info->provides); } } fclose(fp); @@ -771,7 +772,9 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq if(info->replaces) { fputs("%REPLACES%\n", fp); for(lp = info->replaces; lp; lp = lp->next) { - fprintf(fp, "%s\n", (char *)lp->data); + char *depstring = alpm_dep_compute_string(lp->data); + fprintf(fp, "%s\n", depstring); + free(depstring); } fprintf(fp, "\n"); } @@ -830,14 +833,18 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq if(info->conflicts) { fputs("%CONFLICTS%\n", fp); for(lp = info->conflicts; lp; lp = lp->next) { - fprintf(fp, "%s\n", (char *)lp->data); + char *depstring = alpm_dep_compute_string(lp->data); + fprintf(fp, "%s\n", depstring); + free(depstring); } fprintf(fp, "\n"); } if(info->provides) { fputs("%PROVIDES%\n", fp); for(lp = info->provides; lp; lp = lp->next) { - fprintf(fp, "%s\n", (char *)lp->data); + char *depstring = alpm_dep_compute_string(lp->data); + fprintf(fp, "%s\n", depstring); + free(depstring); } fprintf(fp, "\n"); } |