Signed-off-by: Allan McRae <allan@archlinux.org> --- lib/libalpm/be_sync.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 2214edf..00c31a3 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -40,6 +40,7 @@ #include "delta.h" #include "deps.h" #include "dload.h" +#include "filelist.h" static char *get_sync_dir(alpm_handle_t *handle) { @@ -444,6 +445,7 @@ static size_t estimate_package_count(struct stat *st, struct archive *archive) /* assume it is at least somewhat compressed */ per_package = 500; } + return (size_t)((st->st_size / per_package) + 1); } @@ -476,6 +478,11 @@ static int sync_db_populate(alpm_db_t *db) } est_count = estimate_package_count(&buf, archive); + if(db->handle->files) { + /* files databases are about four times larger on average */ + est_count /= 4; + } + db->pkgcache = _alpm_pkghash_create(est_count); if(db->pkgcache == NULL) { db->handle->pm_errno = ALPM_ERR_MEMORY; @@ -606,7 +613,8 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive, } if(strcmp(filename, "desc") == 0 || strcmp(filename, "depends") == 0 - || (strcmp(filename, "deltas") == 0 && db->handle->deltaratio > 0.0) ) { + || (strcmp(filename, "deltas") == 0 && db->handle->deltaratio > 0.0) + || (strcmp(filename, "files") == 0 && db->handle->files == 1)) { int ret; while((ret = _alpm_archive_fgets(archive, &buf)) == ARCHIVE_OK) { char *line = buf.line; @@ -691,6 +699,32 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive, pkg->deltas = alpm_list_add(pkg->deltas, _alpm_delta_parse(db->handle, line)); } + } else if(strcmp(line, "%FILES%") == 0) { + 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) { @@ -700,7 +734,7 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive, } else if(strcmp(filename, "deltas") == 0) { /* skip reading delta files if UseDelta is unset */ } else if(strcmp(filename, "files") == 0) { - /* currently do nothing with this file */ + /* skip reading files file if handle->files is 0 */ } else { /* unknown database file */ _alpm_log(db->handle, ALPM_LOG_DEBUG, "unknown database file: %s\n", filename); -- 2.4.4