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-22-2012, 05:30 PM
Andrew Gregory
 
Default query_fileowner: resolve root early

Resolving root early prevents later calls to realpath from having to do the
work of actually resolving any symlinks in root. Also removes the unnecessary
root variable.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
---
src/pacman/query.c | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/pacman/query.c b/src/pacman/query.c
index bb75465..84c9d3b 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -94,7 +94,6 @@ static int query_fileowner(alpm_list_t *targets)
{
int ret = 0;
char path[PATH_MAX];
- const char *root;
size_t rootlen;
alpm_list_t *t;
alpm_db_t *db_local;
@@ -108,14 +107,23 @@ static int query_fileowner(alpm_list_t *targets)
/* Set up our root path buffer. We only need to copy the location of root in
* once, then we can just overwrite whatever file was there on the previous
* iteration. */
- root = alpm_option_get_root(config->handle);
- rootlen = strlen(root);
- if(rootlen + 1 > PATH_MAX) {
- /* we are in trouble here */
- pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), root, "");
+
+ /* resolve root now so any symlinks will only have to be resolved once */
+ if(!realpath(alpm_option_get_root(config->handle), path)){
+ pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s
"),
+ alpm_option_get_root(config->handle), strerror(errno));
+ }
+
+ /* make sure there's enough room to append the package file to path */
+ rootlen = strlen(path);
+ if(rootlen + 2 > PATH_MAX) {
+ pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), path, "");
return 1;
}
- strcpy(path, root);
+
+ /* append trailing '/' removed by realpath */
+ path[rootlen++] = '/';
+ path[rootlen] = '';

db_local = alpm_get_localdb(config->handle);

@@ -200,7 +208,8 @@ static int query_fileowner(alpm_list_t *targets)
}

if(rootlen + 1 + strlen(pkgfile) > PATH_MAX) {
- pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), root, pkgfile);
+ pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), path, pkgfile);
+ continue;
}
/* concatenate our file and the root path */
strcpy(path + rootlen, pkgfile);
@@ -208,8 +217,15 @@ static int query_fileowner(alpm_list_t *targets)
pdname = mdirname(path);
ppath = realpath(pdname, NULL);
free(pdname);
+ path[rootlen] = ''; /* reset path for error messages */
+
+ if(!ppath) {
+ pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s
"),
+ ppath, strerror(errno));
+ continue;
+ }

- if(ppath && strcmp(ppath, rpath) == 0) {
+ if(strcmp(ppath, rpath) == 0) {
print_query_fileowner(filename, info);
found = 1;
}
--
1.7.11.2
 
Old 07-23-2012, 04:54 AM
Allan McRae
 
Default query_fileowner: resolve root early

On 23/07/12 03:30, Andrew Gregory wrote:
> Resolving root early prevents later calls to realpath from having to do the
> work of actually resolving any symlinks in root. Also removes the unnecessary
> root variable.
>
> Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
> ---
> src/pacman/query.c | 34 +++++++++++++++++++++++++---------
> 1 file changed, 25 insertions(+), 9 deletions(-)
>
> diff --git a/src/pacman/query.c b/src/pacman/query.c
> index bb75465..84c9d3b 100644
> --- a/src/pacman/query.c
> +++ b/src/pacman/query.c
> @@ -94,7 +94,6 @@ static int query_fileowner(alpm_list_t *targets)
> {
> int ret = 0;
> char path[PATH_MAX];
> - const char *root;
> size_t rootlen;
> alpm_list_t *t;
> alpm_db_t *db_local;
> @@ -108,14 +107,23 @@ static int query_fileowner(alpm_list_t *targets)
> /* Set up our root path buffer. We only need to copy the location of root in
> * once, then we can just overwrite whatever file was there on the previous
> * iteration. */
> - root = alpm_option_get_root(config->handle);
> - rootlen = strlen(root);
> - if(rootlen + 1 > PATH_MAX) {
> - /* we are in trouble here */
> - pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), root, "");
> +
> + /* resolve root now so any symlinks will only have to be resolved once */
> + if(!realpath(alpm_option_get_root(config->handle), path)){
> + pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s
"),
> + alpm_option_get_root(config->handle), strerror(errno));

return 1;

> + }
> +
> + /* make sure there's enough room to append the package file to path */
> + rootlen = strlen(path);
> + if(rootlen + 2 > PATH_MAX) {
> + pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), path, "");
> return 1;
> }
> - strcpy(path, root);
> +
> + /* append trailing '/' removed by realpath */
> + path[rootlen++] = '/';
> + path[rootlen] = '';
>
> db_local = alpm_get_localdb(config->handle);
>
> @@ -200,7 +208,8 @@ static int query_fileowner(alpm_list_t *targets)
> }
>
> if(rootlen + 1 + strlen(pkgfile) > PATH_MAX) {
> - pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), root, pkgfile);
> + pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), path, pkgfile);
> + continue;

That continue looks familiar. Please build on top of you previous patch
to avoid confusion and make applying the patch easier:
https://patchwork.archlinux.org/patch/203/
(I know the confusion is mostly our fault given the number of patches
floating around in this area that have not been merged yet...)

> }
> /* concatenate our file and the root path */
> strcpy(path + rootlen, pkgfile);
> @@ -208,8 +217,15 @@ static int query_fileowner(alpm_list_t *targets)
> pdname = mdirname(path);
> ppath = realpath(pdname, NULL);
> free(pdname);
> + path[rootlen] = ''; /* reset path for error messages */
> +
> + if(!ppath) {
> + pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s
"),
> + ppath, strerror(errno));
> + continue;
> + }
>
> - if(ppath && strcmp(ppath, rpath) == 0) {
> + if(strcmp(ppath, rpath) == 0) {
> print_query_fileowner(filename, info);
> found = 1;
> }
>
 
Old 07-26-2012, 05:01 AM
Andrew Gregory
 
Default query_fileowner: resolve root early

Resolving root early prevents later calls to realpath from having to do the
work of actually resolving any symlinks in root.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
---
src/pacman/query.c | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/pacman/query.c b/src/pacman/query.c
index 725e35d..176f91c 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -94,7 +94,6 @@ static int query_fileowner(alpm_list_t *targets)
{
int ret = 0;
char path[PATH_MAX];
- const char *root;
size_t rootlen;
alpm_list_t *t;
alpm_db_t *db_local;
@@ -108,14 +107,24 @@ static int query_fileowner(alpm_list_t *targets)
/* Set up our root path buffer. We only need to copy the location of root in
* once, then we can just overwrite whatever file was there on the previous
* iteration. */
- root = alpm_option_get_root(config->handle);
- rootlen = strlen(root);
- if(rootlen + 1 > PATH_MAX) {
- /* we are in trouble here */
- pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), root, "");
+
+ /* resolve root now so any symlinks in it will only have to be resolved once */
+ if(!realpath(alpm_option_get_root(config->handle), path)) {
+ pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s
"),
+ path, strerror(errno));
return 1;
}
- strcpy(path, root);
+
+ /* make sure there's enough room to append the package file to path */
+ rootlen = strlen(path);
+ if(rootlen + 2 > PATH_MAX) {
+ pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), path, "");
+ return 1;
+ }
+
+ /* append trailing '/' removed by realpath */
+ path[rootlen++] = '/';
+ path[rootlen] = '';

db_local = alpm_get_localdb(config->handle);

@@ -201,7 +210,7 @@ static int query_fileowner(alpm_list_t *targets)
}

if(rootlen + 1 + strlen(pkgfile) > PATH_MAX) {
- pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), root, pkgfile);
+ pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s
"), path, pkgfile);
continue;
}
/* concatenate our file and the root path */
@@ -210,8 +219,15 @@ static int query_fileowner(alpm_list_t *targets)
pdname = mdirname(path);
ppath = realpath(pdname, NULL);
free(pdname);
+ path[rootlen] = ''; /* reset path for error messages */
+
+ if(!ppath) {
+ pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s
"),
+ pdname, strerror(errno));
+ continue;
+ }

- if(ppath && strcmp(ppath, rpath) == 0) {
+ if(strcmp(ppath, rpath) == 0) {
print_query_fileowner(filename, info);
found = 1;
free(ppath);
--
1.7.11.3
 
Old 07-26-2012, 05:39 AM
Allan McRae
 
Default query_fileowner: resolve root early

On 26/07/12 15:01, Andrew Gregory wrote:
> Resolving root early prevents later calls to realpath from having to do the
> work of actually resolving any symlinks in root.
>
> Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>

Ack.

Allan
 

Thread Tools




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

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