add_entry_to_files_list: pass filelist directly

Allows entries to be added to arbitrary filelists not connected to
a package.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Andrew Gregory 2015-03-25 05:53:06 -04:00 committed by Allan McRae
parent bf3aec8c32
commit edeafcc988

View file

@ -384,15 +384,16 @@ static int handle_simple_path(alpm_pkg_t *pkg, const char *path)
* @param path path of the file to be added * @param path path of the file to be added
* @return <0 on error, 0 on success * @return <0 on error, 0 on success
*/ */
static int add_entry_to_files_list(alpm_pkg_t *pkg, size_t *files_size, static int add_entry_to_files_list(alpm_filelist_t *filelist,
struct archive_entry *entry, const char *path) size_t *files_size, struct archive_entry *entry, const char *path)
{ {
const size_t files_count = pkg->files.count; const size_t files_count = filelist->count;
alpm_file_t *current_file; alpm_file_t *current_file;
mode_t type; mode_t type;
size_t pathlen; size_t pathlen;
if(!_alpm_greedy_grow((void **)&pkg->files.files, files_size, (files_count + 1) * sizeof(alpm_file_t))) { if(!_alpm_greedy_grow((void **)&filelist->files,
files_size, (files_count + 1) * sizeof(alpm_file_t))) {
return -1; return -1;
} }
@ -400,7 +401,7 @@ static int add_entry_to_files_list(alpm_pkg_t *pkg, size_t *files_size,
pathlen = strlen(path); pathlen = strlen(path);
current_file = pkg->files.files + files_count; current_file = filelist->files + files_count;
/* mtree paths don't contain a tailing slash, those we get from /* mtree paths don't contain a tailing slash, those we get from
* the archive directly do (expensive way) * the archive directly do (expensive way)
@ -418,7 +419,7 @@ static int add_entry_to_files_list(alpm_pkg_t *pkg, size_t *files_size,
} }
current_file->size = archive_entry_size(entry); current_file->size = archive_entry_size(entry);
current_file->mode = archive_entry_mode(entry); current_file->mode = archive_entry_mode(entry);
pkg->files.count++; filelist->count++;
return 0; return 0;
} }
@ -509,7 +510,7 @@ static int build_filelist_from_mtree(alpm_handle_t *handle, alpm_pkg_t *pkg, str
continue; continue;
} }
if(add_entry_to_files_list(pkg, &files_size, mtree_entry, path) < 0) { if(add_entry_to_files_list(&pkg->files, &files_size, mtree_entry, path) < 0) {
goto error; goto error;
} }
} }
@ -617,7 +618,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
continue; continue;
} else if(full && !hit_mtree) { } else if(full && !hit_mtree) {
/* building the file list: expensive way */ /* building the file list: expensive way */
if(add_entry_to_files_list(newpkg, &files_size, entry, entry_name) < 0) { if(add_entry_to_files_list(&newpkg->files, &files_size, entry, entry_name) < 0) {
goto error; goto error;
} }
} }