[pacman-dev] [PATCH 3/5] _alpm_filelist_resolve: use original filenames where possible
Allan McRae
allan at archlinux.org
Sun Jul 29 02:18:33 EDT 2012
From: Andrew Gregory <andrew.gregory.8 at gmail.com>
If a filename isn't resolved, the original can be used instead of strdup()ing
it.
Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
---
lib/libalpm/filelist.c | 8 ++++----
lib/libalpm/package.c | 19 +++++++++++++------
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/lib/libalpm/filelist.c b/lib/libalpm/filelist.c
index d32a3e5..288907a 100644
--- a/lib/libalpm/filelist.c
+++ b/lib/libalpm/filelist.c
@@ -80,7 +80,7 @@ size_t _alpm_filelist_resolve_link(
if(resolving) {
if(f_len + causal_dir_r_len - causal_dir_len > PATH_MAX) {
- files->resolved_path[i] = strdup(filename);
+ files->resolved_path[i] = filename;
continue;
}
@@ -97,7 +97,7 @@ size_t _alpm_filelist_resolve_link(
/* deal with files and paths too long to resolve*/
if(filename[f_len-1] != '/') {
- files->resolved_path[i] = strdup(filename_r);
+ files->resolved_path[i] = resolving ? strdup(filename_r) : filename;
continue;
}
@@ -112,7 +112,7 @@ size_t _alpm_filelist_resolve_link(
}
/* deal with normal directories */
- files->resolved_path[i] = strdup(filename_r);
+ files->resolved_path[i] = resolving ? strdup(filename_r) : filename;
/* deal with children of non-existent directories to reduce lstat() calls */
if (!exists) {
@@ -124,7 +124,7 @@ size_t _alpm_filelist_resolve_link(
strcpy(filename_r + causal_dir_r_len, f + causal_dir_len);
files->resolved_path[i] = strdup(filename_r);
} else {
- files->resolved_path[i] = strdup(f);
+ files->resolved_path[i] = f;
}
i++;
}
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index ab84329..4887e21 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -591,17 +591,24 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
free_deplist(pkg->replaces);
FREELIST(pkg->groups);
if(pkg->files.count) {
- size_t i;
- for(i = 0; i < pkg->files.count; i++) {
- FREE(pkg->files.files[i].name);
- }
- free(pkg->files.files);
+ size_t i, j, k;
if(pkg->files.resolved_path) {
- for(i = 0; i < pkg->files.count; i++) {
+ for(i = 0, j = 0; i < pkg->files.count; i++) {
+ for(k = j; k <= pkg->files.count; k++) {
+ if(pkg->files.resolved_path[i] == pkg->files.files[k].name) {
+ pkg->files.files[k].name = NULL;
+ j = k + 1;
+ break;
+ }
+ }
free(pkg->files.resolved_path[i]);
}
free(pkg->files.resolved_path);
}
+ for(j = 0; j < pkg->files.count; j++) {
+ FREE(pkg->files.files[j].name);
+ }
+ free(pkg->files.files);
}
alpm_list_free_inner(pkg->backup, (alpm_list_fn_free)_alpm_backup_free);
alpm_list_free(pkg->backup);
--
1.7.11.3
More information about the pacman-dev
mailing list