[pacman-dev] [PATCH 2/3] Merge desc and depends files in local db
Whenever depends is needed from the local db, so is desc. The only disadvantage to merging them is the additional time taken to read the depends entries when they are not needed. As depends is in general relatively small, the additional time taken to read it in will be negligable. Also, merging these files will speed up local database access due to less file seeks. Signed-off-by: Allan McRae <allan@archlinux.org> --- lib/libalpm/be_local.c | 144 ++++++++++++++++++---------------------------- lib/libalpm/be_package.c | 2 +- lib/libalpm/db.h | 9 +-- 3 files changed, 61 insertions(+), 94 deletions(-) diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 2212752..4574bd4 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -165,25 +165,25 @@ int _cache_get_epoch(pmpkg_t *pkg) alpm_list_t *_cache_get_depends(pmpkg_t *pkg) { - LAZY_LOAD(INFRQ_DEPENDS, NULL); + LAZY_LOAD(INFRQ_DESC, NULL); return pkg->depends; } alpm_list_t *_cache_get_optdepends(pmpkg_t *pkg) { - LAZY_LOAD(INFRQ_DEPENDS, NULL); + LAZY_LOAD(INFRQ_DESC, NULL); return pkg->optdepends; } alpm_list_t *_cache_get_conflicts(pmpkg_t *pkg) { - LAZY_LOAD(INFRQ_DEPENDS, NULL); + LAZY_LOAD(INFRQ_DESC, NULL); return pkg->conflicts; } alpm_list_t *_cache_get_provides(pmpkg_t *pkg) { - LAZY_LOAD(INFRQ_DEPENDS, NULL); + LAZY_LOAD(INFRQ_DESC, NULL); return pkg->provides; } @@ -614,32 +614,28 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) if(!info->epoch) { info->epoch = 1; } - } - } - fclose(fp); - fp = NULL; - } - - /* FILES */ - if(inforeq & INFRQ_FILES) { - snprintf(path, PATH_MAX, "%sfiles", pkgpath); - if((fp = fopen(path, "r")) == NULL) { - _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno)); - goto error; - } - while(fgets(line, sizeof(line), fp)) { - _alpm_strtrim(line); - if(strcmp(line, "%FILES%") == 0) { + } else if(strcmp(line, "%DEPENDS%") == 0) { + while(fgets(line, sizeof(line), fp) && strlen(_alpm_strtrim(line))) { + pmdepend_t *dep = _alpm_splitdep(_alpm_strtrim(line)); + info->depends = alpm_list_add(info->depends, dep); + } + } else if(strcmp(line, "%OPTDEPENDS%") == 0) { while(fgets(line, sizeof(line), fp) && strlen(_alpm_strtrim(line))) { char *linedup; STRDUP(linedup, _alpm_strtrim(line), goto error); - info->files = alpm_list_add(info->files, linedup); + info->optdepends = alpm_list_add(info->optdepends, linedup); } - } else if(strcmp(line, "%BACKUP%") == 0) { + } else if(strcmp(line, "%CONFLICTS%") == 0) { while(fgets(line, sizeof(line), fp) && strlen(_alpm_strtrim(line))) { char *linedup; STRDUP(linedup, _alpm_strtrim(line), goto error); - info->backup = alpm_list_add(info->backup, linedup); + info->conflicts = alpm_list_add(info->conflicts, linedup); + } + } else if(strcmp(line, "%PROVIDES%") == 0) { + while(fgets(line, sizeof(line), fp) && strlen(_alpm_strtrim(line))) { + char *linedup; + STRDUP(linedup, _alpm_strtrim(line), goto error); + info->provides = alpm_list_add(info->provides, linedup); } } } @@ -647,40 +643,26 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) fp = NULL; } - /* DEPENDS */ - if(inforeq & INFRQ_DEPENDS) { - snprintf(path, PATH_MAX, "%sdepends", pkgpath); + /* FILES */ + if(inforeq & INFRQ_FILES) { + snprintf(path, PATH_MAX, "%sfiles", pkgpath); if((fp = fopen(path, "r")) == NULL) { _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno)); goto error; } - while(!feof(fp)) { - if(fgets(line, sizeof(line), fp) == NULL) { - break; - } + while(fgets(line, sizeof(line), fp)) { _alpm_strtrim(line); - if(strcmp(line, "%DEPENDS%") == 0) { - while(fgets(line, sizeof(line), fp) && strlen(_alpm_strtrim(line))) { - pmdepend_t *dep = _alpm_splitdep(_alpm_strtrim(line)); - info->depends = alpm_list_add(info->depends, dep); - } - } else if(strcmp(line, "%OPTDEPENDS%") == 0) { - while(fgets(line, sizeof(line), fp) && strlen(_alpm_strtrim(line))) { - char *linedup; - STRDUP(linedup, _alpm_strtrim(line), goto error); - info->optdepends = alpm_list_add(info->optdepends, linedup); - } - } else if(strcmp(line, "%CONFLICTS%") == 0) { + if(strcmp(line, "%FILES%") == 0) { while(fgets(line, sizeof(line), fp) && strlen(_alpm_strtrim(line))) { char *linedup; STRDUP(linedup, _alpm_strtrim(line), goto error); - info->conflicts = alpm_list_add(info->conflicts, linedup); + info->files = alpm_list_add(info->files, linedup); } - } else if(strcmp(line, "%PROVIDES%") == 0) { + } else if(strcmp(line, "%BACKUP%") == 0) { while(fgets(line, sizeof(line), fp) && strlen(_alpm_strtrim(line))) { char *linedup; STRDUP(linedup, _alpm_strtrim(line), goto error); - info->provides = alpm_list_add(info->provides, linedup); + info->backup = alpm_list_add(info->backup, linedup); } } } @@ -828,49 +810,6 @@ int _alpm_local_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) fprintf(fp, "%%REASON%%\n" "%u\n\n", info->reason); } - - fclose(fp); - fp = NULL; - } - - /* FILES */ - if(inforeq & INFRQ_FILES) { - _alpm_log(PM_LOG_DEBUG, "writing %s-%s FILES information back to db\n", - info->name, info->version); - snprintf(path, PATH_MAX, "%sfiles", pkgpath); - if((fp = fopen(path, "w")) == NULL) { - _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno)); - retval = -1; - goto cleanup; - } - if(info->files) { - fprintf(fp, "%%FILES%%\n"); - for(lp = info->files; lp; lp = lp->next) { - fprintf(fp, "%s\n", (char *)lp->data); - } - fprintf(fp, "\n"); - } - if(info->backup) { - fprintf(fp, "%%BACKUP%%\n"); - for(lp = info->backup; lp; lp = lp->next) { - fprintf(fp, "%s\n", (char *)lp->data); - } - fprintf(fp, "\n"); - } - fclose(fp); - fp = NULL; - } - - /* DEPENDS */ - if(inforeq & INFRQ_DEPENDS) { - _alpm_log(PM_LOG_DEBUG, "writing %s-%s DEPENDS information back to db\n", - info->name, info->version); - snprintf(path, PATH_MAX, "%sdepends", pkgpath); - if((fp = fopen(path, "w")) == NULL) { - _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno)); - retval = -1; - goto cleanup; - } if(info->depends) { fputs("%DEPENDS%\n", fp); for(lp = info->depends; lp; lp = lp->next) { @@ -901,6 +840,35 @@ int _alpm_local_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) } fprintf(fp, "\n"); } + + fclose(fp); + fp = NULL; + } + + /* FILES */ + if(inforeq & INFRQ_FILES) { + _alpm_log(PM_LOG_DEBUG, "writing %s-%s FILES information back to db\n", + info->name, info->version); + snprintf(path, PATH_MAX, "%sfiles", pkgpath); + if((fp = fopen(path, "w")) == NULL) { + _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno)); + retval = -1; + goto cleanup; + } + if(info->files) { + fprintf(fp, "%%FILES%%\n"); + for(lp = info->files; lp; lp = lp->next) { + fprintf(fp, "%s\n", (char *)lp->data); + } + fprintf(fp, "\n"); + } + if(info->backup) { + fprintf(fp, "%%BACKUP%%\n"); + for(lp = info->backup; lp; lp = lp->next) { + fprintf(fp, "%s\n", (char *)lp->data); + } + fprintf(fp, "\n"); + } fclose(fp); fp = NULL; } diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index 254f830..d63ab1f 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -363,7 +363,7 @@ static pmpkg_t *pkg_load(const char *pkgfile, int full) } else { /* get rid of any partial filelist we may have collected, it is invalid */ FREELIST(newpkg->files); - newpkg->infolevel = INFRQ_BASE | INFRQ_DESC | INFRQ_DEPENDS; + newpkg->infolevel = INFRQ_BASE | INFRQ_DESC; } return(newpkg); diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index 5352e9e..133b095 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -34,12 +34,11 @@ typedef enum _pmdbinfrq_t { INFRQ_BASE = 1, INFRQ_DESC = (1 << 1), - INFRQ_DEPENDS = (1 << 2), - INFRQ_FILES = (1 << 3), - INFRQ_SCRIPTLET = (1 << 4), - INFRQ_DSIZE = (1 << 5), + INFRQ_FILES = (1 << 2), + INFRQ_SCRIPTLET = (1 << 3), + INFRQ_DSIZE = (1 << 4), /* ALL should be info stored in the package or database */ - INFRQ_ALL = 0x3F + INFRQ_ALL = 0x1F } pmdbinfrq_t; struct db_operations { -- 1.7.3.2
On 30/10/10 16:03, Allan McRae wrote:
Whenever depends is needed from the local db, so is desc. The only disadvantage to merging them is the additional time taken to read the depends entries when they are not needed. As depends is in general relatively small, the additional time taken to read it in will be negligable. Also, merging these files will speed up local database access due to less file seeks.
Of course this is going to need a nice post_install script for the next major pacman release... or now for those of us using the git version once this is pushed. I'm testing one out now. Allan
On 30/10/10 16:19, Allan McRae wrote:
On 30/10/10 16:03, Allan McRae wrote:
Whenever depends is needed from the local db, so is desc. The only disadvantage to merging them is the additional time taken to read the depends entries when they are not needed. As depends is in general relatively small, the additional time taken to read it in will be negligable. Also, merging these files will speed up local database access due to less file seeks.
Of course this is going to need a nice post_install script for the next major pacman release... or now for those of us using the git version once this is pushed.
I'm testing one out now.
Here it goes: -- start -- DBPATH=/var/lib/pacman/local for i in $DBPATH/*; do if [[ -f $i/depends ]]; then cat $i/depends >> $i/desc rm $i/depends fi done -- end -- If you are going to test these patches before they are accepted to master, I suggest you copy your local db elsewhere and change DBPATH in that script. Then you can use pacman with --dbpath (but do not do anything that modifies the local db...) Allan
participants (1)
-
Allan McRae