diff options
author | Andrew Gregory <andrew.gregory.8@gmail.com> | 2012-08-07 04:18:14 +0200 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2012-12-14 03:35:34 +0100 |
commit | 28d404f16aca8ae1b7640b32c221c8b8860f8ce0 (patch) | |
tree | b8037499ff2597872710934346984fdc1462361c | |
parent | 80bc89c14768590e6ce3d33efaea8852a4db586c (diff) | |
download | pacman-28d404f16aca8ae1b7640b32c221c8b8860f8ce0.tar.gz pacman-28d404f16aca8ae1b7640b32c221c8b8860f8ce0.tar.xz |
_alpm_filelist_resolve: use original filenames where possible
If a filename isn't resolved, the original can be used instead of strdup()ing
it.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r-- | lib/libalpm/filelist.c | 37 | ||||
-rw-r--r-- | lib/libalpm/package.c | 19 |
2 files changed, 34 insertions, 22 deletions
diff --git a/lib/libalpm/filelist.c b/lib/libalpm/filelist.c index 0a62a2dc..a3f63970 100644 --- a/lib/libalpm/filelist.c +++ b/lib/libalpm/filelist.c @@ -57,13 +57,13 @@ size_t _alpm_filelist_resolve_link( causal_dir = files->files[i].name; causal_dir_len = strlen(causal_dir); if(realpath(path, filename_r) == NULL) { - STRDUP(files->resolved_path[i], causal_dir, goto error); + files->resolved_path[i] = causal_dir; FREE(filename_r); return i; } causal_dir_r_len = strlen(filename_r + root_len) + 1; if(causal_dir_r_len >= PATH_MAX) { - STRDUP(files->resolved_path[i], causal_dir, goto error); + files->resolved_path[i] = causal_dir; FREE(filename_r); return i; } @@ -91,23 +91,25 @@ size_t _alpm_filelist_resolve_link( filename_r_len = filename_len + causal_dir_r_len - causal_dir_len; if(filename_r_len >= PATH_MAX) { /* resolved path is too long */ - STRDUP(files->resolved_path[i], filename, goto error); + files->resolved_path[i] = filename; continue; } strcpy(filename_r + causal_dir_r_len, filename + causal_dir_len); - } else { - filename_r = filename; } /* deal with files and paths too long to resolve*/ if(filename[filename_len - 1] != '/' || root_len + filename_r_len >= PATH_MAX) { - STRDUP(files->resolved_path[i], filename_r, goto error); + if(resolving) { + STRDUP(files->resolved_path[i], filename_r, goto error); + } else { + files->resolved_path[i] = filename; + } continue; } /* construct absolute path and stat() */ - strcpy(path + root_len, filename_r); + strcpy(path + root_len, resolving ? filename_r : filename); exists = !_alpm_lstat(path, &sbuf); /* deal with symlinks */ @@ -117,7 +119,11 @@ size_t _alpm_filelist_resolve_link( } /* deal with normal directories */ - STRDUP(files->resolved_path[i], filename_r, goto error); + if(resolving) { + STRDUP(files->resolved_path[i], filename_r, goto error); + } else { + files->resolved_path[i] = filename; + } /* deal with children of non-existent directories to reduce lstat() calls */ if (!exists) { @@ -136,25 +142,24 @@ size_t _alpm_filelist_resolve_link( strcpy(filename_r + causal_dir_r_len, f + causal_dir_len); STRDUP(files->resolved_path[i], filename_r, goto error); } else { - STRDUP(files->resolved_path[i], f, goto error); + files->resolved_path[i] = f; } } i--; } } - if(resolving) { - FREE(filename_r); - } + FREE(filename_r); return i-1; error: - if(resolving) { - FREE(filename_r); + FREE(filename_r); + /* out of memory, set remaining files to their original names */ + for(; i < files->count; (i)++) { + files->resolved_path[i] = files->files[i].name; } - /* out of memory, not much point in going on */ - return files->count; + return i-1; } /** diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index ab84329c..4887e215 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); |