Add resolved_path to alpm_filelist_t

Add an array to hold the resolved paths of the files in alpm_filelist_t.
When the file name and its resolved file name are identical, the pointer
to the original file name is used to avoid duplicate memory allocation.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2012-07-18 23:34:32 +10:00
parent c1abfeae1e
commit 2fad78974d
2 changed files with 11 additions and 1 deletions

View file

@ -210,6 +210,7 @@ typedef struct _alpm_file_t {
typedef struct _alpm_filelist_t { typedef struct _alpm_filelist_t {
size_t count; size_t count;
alpm_file_t *files; alpm_file_t *files;
char **resolved_path;
} alpm_filelist_t; } alpm_filelist_t;
/** Local package or package file backup entry */ /** Local package or package file backup entry */

View file

@ -540,6 +540,9 @@ int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr)
} }
} }
newpkg->files.count = pkg->files.count; newpkg->files.count = pkg->files.count;
/* deliberately do not copy resolved_path as this is only used
* during conflict checking and the sorting of list does not readily
* allow keeping its efficient memory usage when copying */
} }
/* internal */ /* internal */
@ -590,9 +593,15 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
if(pkg->files.count) { if(pkg->files.count) {
size_t i; size_t i;
for(i = 0; i < pkg->files.count; i++) { for(i = 0; i < pkg->files.count; i++) {
free(pkg->files.files[i].name); FREE(pkg->files.files[i].name);
} }
free(pkg->files.files); free(pkg->files.files);
if(pkg->files.resolved_path) {
for(i = 0; i < pkg->files.count; i++) {
free(pkg->files.resolved_path[i]);
}
free(pkg->files.resolved_path);
}
} }
alpm_list_free_inner(pkg->backup, (alpm_list_fn_free)_alpm_backup_free); alpm_list_free_inner(pkg->backup, (alpm_list_fn_free)_alpm_backup_free);
alpm_list_free(pkg->backup); alpm_list_free(pkg->backup);