[pacman-dev] [PATCH 0/4] Miscellaneous query_fileowner cleanup
These patches apply on top of my previous query.c patches sitting in Allan's working-split/query-owner branch. Also available under the dirowner_split branch of my repo at https://bitbucket.org/andrewgregory/pacman
Returning "/" from mdirname removes it as a special case which allows us to
test it like any other directory. This corrects a false positive when querying
a file in / and root is not set to /.
Signed-off-by: Andrew Gregory
On 12/08/12 07:35, Andrew Gregory wrote:
Returning "/" from mdirname removes it as a special case which allows us to test it like any other directory. This corrects a false positive when querying a file in / and root is not set to /.
Signed-off-by: Andrew Gregory
--- src/pacman/query.c | 31 ++++++------------------------- src/pacman/util.c | 5 +++++ 2 files changed, 11 insertions(+), 25 deletions(-)
Ack-by: Allan Sorry it took so long to get to looking at these patches.
Also consolidates cleanup for query_fileowner.
Signed-off-by: Andrew Gregory
On 12/08/12 07:35, Andrew Gregory wrote:
Also consolidates cleanup for query_fileowner.
Signed-off-by: Andrew Gregory
--- src/pacman/query.c | 28 ++++++++++++++-------------- src/pacman/util.c | 5 ++++- 2 files changed, 18 insertions(+), 15 deletions(-)
<snip>
diff --git a/src/pacman/util.c b/src/pacman/util.c index 2d1b762..ba7a8c0 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -239,7 +239,10 @@ char *mdirname(const char *path) return strdup("."); }
- ret = strdup(path); + if((ret = strdup(path)) == NULL) { + return NULL;
Whitespace error. Fixed on my working branch.
+ } + last = strrchr(ret, '/');
if(last != NULL) {
Signed-off-by: Andrew Gregory
On 12/08/12 07:35, Andrew Gregory wrote:
Signed-off-by: Andrew Gregory
--- src/pacman/query.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pacman/query.c b/src/pacman/query.c index 9afe680..d882e5a 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -123,8 +123,10 @@ static int query_fileowner(alpm_list_t *targets) }
/* append trailing '/' removed by realpath */ - path[rootlen++] = '/'; - path[rootlen] = '\0'; + if(strcmp(path, "/") != 0) {
Given this is the uncommon case, can we change this to the less expensive: if(rootlen == 1 && path[0] == '/')
+ path[rootlen++] = '/'; + path[rootlen] = '\0'; + }
db_local = alpm_get_localdb(config->handle);
On Mon, 27 Aug 2012 17:24:54 +1000
Allan McRae
On 12/08/12 07:35, Andrew Gregory wrote:
Signed-off-by: Andrew Gregory
--- src/pacman/query.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pacman/query.c b/src/pacman/query.c index 9afe680..d882e5a 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -123,8 +123,10 @@ static int query_fileowner(alpm_list_t *targets) }
/* append trailing '/' removed by realpath */ - path[rootlen++] = '/'; - path[rootlen] = '\0'; + if(strcmp(path, "/") != 0) {
Given this is the uncommon case, can we change this to the less expensive:
if(rootlen == 1 && path[0] == '/')
Sure, but we may as well make it more generalized too by just testing for a trailing '/' with: if(path[rootlen - 1] != '/')
+ path[rootlen++] = '/'; + path[rootlen] = '\0'; + }
db_local = alpm_get_localdb(config->handle);
On 28/08/12 14:34, Andrew Gregory wrote:
On Mon, 27 Aug 2012 17:24:54 +1000 Allan McRae
wrote: On 12/08/12 07:35, Andrew Gregory wrote:
Signed-off-by: Andrew Gregory
--- src/pacman/query.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pacman/query.c b/src/pacman/query.c index 9afe680..d882e5a 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -123,8 +123,10 @@ static int query_fileowner(alpm_list_t *targets) }
/* append trailing '/' removed by realpath */ - path[rootlen++] = '/'; - path[rootlen] = '\0'; + if(strcmp(path, "/") != 0) {
Given this is the uncommon case, can we change this to the less expensive:
if(rootlen == 1 && path[0] == '/')
Sure, but we may as well make it more generalized too by just testing for a trailing '/' with:
if(path[rootlen - 1] != '/')
Of course! Send it through. Allan
Signed-off-by: Andrew Gregory
--- src/pacman/query.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pacman/query.c b/src/pacman/query.c index d882e5a..7381c4e 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -58,7 +58,7 @@ static int search_path(char **filename, struct stat *bufptr) /* strip the trailing slash if one exists */ while(path[plen - 1] == '/') { - path[--plen] = '\0'; + path[--plen] = '\0'; } fullname = malloc(plen + flen + 2); @@ -144,7 +144,7 @@ static int query_fileowner(alpm_list_t *targets) /* trailing '/' causes lstat to dereference directory symlinks */ len = strlen(filename) - 1; - while(len > 0 && filename[len] == '/'){ + while(len > 0 && filename[len] == '/') { filename[len--] = '\0'; } -- 1.7.11.4
participants (2)
-
Allan McRae
-
Andrew Gregory