summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/be_local.c
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2010-10-30 07:35:43 +0200
committerDan McGee <dan@archlinux.org>2010-12-13 04:42:41 +0100
commit21833d90e26635fdd2c6af247790a9bf374b4d80 (patch)
tree3f386dc01e2016c2c9c7003ec2590d4931769259 /lib/libalpm/be_local.c
parent209d0643e5fd38f8add70cfb3651012993d861f1 (diff)
downloadpacman-21833d90e26635fdd2c6af247790a9bf374b4d80.tar.gz
pacman-21833d90e26635fdd2c6af247790a9bf374b4d80.tar.xz
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> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/be_local.c')
-rw-r--r--lib/libalpm/be_local.c144
1 files changed, 56 insertions, 88 deletions
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 988248d8..9dce66df 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;
}