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

Read file lists from databases

If a sync database contains a "files" file, the file list will be read.

Currently, there is no known demand for the file list to be lazy loaded by
any libalpm frontend, so these files are read whenever present. Lazy loading
can be implemented when a demand exists.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2015-07-14 22:00:38 +10:00
parent f6c55b3c3f
commit 289fdf0d1d

View File

@ -40,6 +40,7 @@
#include "delta.h" #include "delta.h"
#include "deps.h" #include "deps.h"
#include "dload.h" #include "dload.h"
#include "filelist.h"
static char *get_sync_dir(alpm_handle_t *handle) static char *get_sync_dir(alpm_handle_t *handle)
{ {
@ -438,6 +439,7 @@ static size_t estimate_package_count(struct stat *st, struct archive *archive)
/* assume it is at least somewhat compressed */ /* assume it is at least somewhat compressed */
per_package = 500; per_package = 500;
} }
return (size_t)((st->st_size / per_package) + 1); return (size_t)((st->st_size / per_package) + 1);
} }
@ -470,6 +472,12 @@ static int sync_db_populate(alpm_db_t *db)
} }
est_count = estimate_package_count(&buf, archive); est_count = estimate_package_count(&buf, archive);
/* currently only .files dbs contain file lists - make flexible when required*/
if(strcmp(db->handle->dbext, ".files") == 0) {
/* files databases are about four times larger on average */
est_count /= 4;
}
db->pkgcache = _alpm_pkghash_create(est_count); db->pkgcache = _alpm_pkghash_create(est_count);
if(db->pkgcache == NULL) { if(db->pkgcache == NULL) {
db->handle->pm_errno = ALPM_ERR_MEMORY; db->handle->pm_errno = ALPM_ERR_MEMORY;
@ -600,6 +608,7 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
} }
if(strcmp(filename, "desc") == 0 || strcmp(filename, "depends") == 0 if(strcmp(filename, "desc") == 0 || strcmp(filename, "depends") == 0
|| strcmp(filename, "files") == 0
|| (strcmp(filename, "deltas") == 0 && db->handle->deltaratio > 0.0) ) { || (strcmp(filename, "deltas") == 0 && db->handle->deltaratio > 0.0) ) {
int ret; int ret;
while((ret = _alpm_archive_fgets(archive, &buf)) == ARCHIVE_OK) { while((ret = _alpm_archive_fgets(archive, &buf)) == ARCHIVE_OK) {
@ -685,6 +694,33 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
pkg->deltas = alpm_list_add(pkg->deltas, pkg->deltas = alpm_list_add(pkg->deltas,
_alpm_delta_parse(db->handle, line)); _alpm_delta_parse(db->handle, line));
} }
} else if(strcmp(line, "%FILES%") == 0) {
/* TODO: this could lazy load if there is future demand */
size_t files_count = 0, files_size = 0;
alpm_file_t *files = NULL;
while(1) {
if(_alpm_archive_fgets(archive, &buf) != ARCHIVE_OK) {
goto error;
}
line = buf.line;
if(_alpm_strip_newline(line, buf.real_line_size) == 0) {
break;
}
if(!_alpm_greedy_grow((void **)&files, &files_size,
(files_count ? (files_count + 1) * sizeof(alpm_file_t) : 8 * sizeof(alpm_file_t)))) {
goto error;
}
STRDUP(files[files_count].name, line, goto error);
files_count++;
}
/* attempt to hand back any memory we don't need */
files = realloc(files, sizeof(alpm_file_t) * files_count);
/* make sure the list is sorted */
qsort(files, files_count, sizeof(alpm_file_t), _alpm_files_cmp);
pkg->files.count = files_count;
pkg->files.files = files;
} }
} }
if(ret != ARCHIVE_EOF) { if(ret != ARCHIVE_EOF) {
@ -693,8 +729,6 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
*likely_pkg = pkg; *likely_pkg = pkg;
} else if(strcmp(filename, "deltas") == 0) { } else if(strcmp(filename, "deltas") == 0) {
/* skip reading delta files if UseDelta is unset */ /* skip reading delta files if UseDelta is unset */
} else if(strcmp(filename, "files") == 0) {
/* currently do nothing with this file */
} else { } else {
/* unknown database file */ /* unknown database file */
_alpm_log(db->handle, ALPM_LOG_DEBUG, "unknown database file: %s\n", filename); _alpm_log(db->handle, ALPM_LOG_DEBUG, "unknown database file: %s\n", filename);