FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 07-29-2012, 06:18 AM
Allan McRae
 
Default _alpm_filelist_resolve: use original filenames where possible

From: Andrew Gregory <andrew.gregory.8@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@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
 
Old 08-07-2012, 02:18 AM
Andrew Gregory
 
Default _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>
---
Modified to account for changes to the previous patch.
lib/libalpm/filelist.c | 37 +++++++++++++++++++++----------------
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 783c8bf..58b1971 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 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.4
 

Thread Tools




All times are GMT. The time now is 07:07 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org