1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

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>
This commit is contained in:
Allan McRae 2010-10-30 15:35:43 +10:00 committed by Dan McGee
parent 209d0643e5
commit 21833d90e2
3 changed files with 61 additions and 94 deletions

View File

@ -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,6 +614,29 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
if(!info->epoch) {
info->epoch = 1;
}
} 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->optdepends = alpm_list_add(info->optdepends, linedup);
}
} 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->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);
}
}
}
fclose(fp);
@ -647,47 +670,6 @@ 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);
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;
}
_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) {
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);
}
} 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);
}
}
}
fclose(fp);
fp = NULL;
}
/* INSTALL */
if(inforeq & INFRQ_SCRIPTLET) {
snprintf(path, PATH_MAX, "%sinstall", pkgpath);
@ -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;
}

View File

@ -362,7 +362,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);

View File

@ -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 {