diff options
author | Aaron Griffin <aaron@archlinux.org> | 2007-03-22 07:32:54 +0000 |
---|---|---|
committer | Aaron Griffin <aaron@archlinux.org> | 2007-03-22 07:32:54 +0000 |
commit | 3aa0c85716bd854cd88bd8df53ce6811cbf90ef0 (patch) | |
tree | 1ca53c0050d540ae6caec0cddc3873a7e923f6a1 /src | |
parent | d7630172337b1ca326d88a23b0842f6ee935cd17 (diff) | |
download | pacman-3aa0c85716bd854cd88bd8df53ce6811cbf90ef0.tar.xz |
* -Qo now properly resolves paths when finding an owner
NOTE that we do NOT want symlinked *files* resolved, only paths (i.e.
/usr/lib/perl5/site_perl/*)
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/query.c | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/src/pacman/query.c b/src/pacman/query.c index ec7d6066..a6ebddb0 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -28,6 +28,7 @@ #include <sys/stat.h> #include <libintl.h> #include <errno.h> +#include <unistd.h> #include <alpm.h> #include <alpm_list.h> @@ -43,11 +44,43 @@ extern config_t *config; extern pmdb_t *db_local; +static char *resolve_path(const char* file) +{ + char *copy, *p, *str = NULL; + + if(!(copy = strdup(file))) { + return(NULL); + } + + if((p = strrchr(copy, '/')) == NULL) { + return(copy); + } else { + *p = '\0'; ++p; + + str = calloc(PATH_MAX+1, sizeof(char)); + if(!str) { + /* null hmmm.... */ + return(NULL); + } + + if(!realpath(copy, str)) { + return(NULL); + } + + str[strlen(str)] = '/'; + strcat(str, p); + } + + free(copy); + return(str); +} + + static void query_fileowner(pmdb_t *db, char *filename) { struct stat buf; int gotcha = 0; - char rpath[PATH_MAX]; + char *rpath; alpm_list_t *i, *j; if(db == NULL) { @@ -68,7 +101,7 @@ static void query_fileowner(pmdb_t *db, char *filename) return; } - if(realpath(filename, rpath) == NULL) { + if(!(rpath = resolve_path(filename))) { ERR(NL, _("cannot determine real path for '%s': %s"), filename, strerror(errno)); return; } @@ -77,20 +110,24 @@ static void query_fileowner(pmdb_t *db, char *filename) pmpkg_t *info = alpm_list_getdata(i); for(j = alpm_pkg_get_files(info); j && !gotcha; j = alpm_list_next(j)) { - char path[PATH_MAX]; - char *filename = alpm_list_getdata(j); - snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), filename); + char path[PATH_MAX], *ppath; + snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), (const char *)alpm_list_getdata(j)); + + ppath = resolve_path(path); - if(strcmp(path, rpath) == 0) { - printf(_("%s is owned by %s %s\n"), path, alpm_pkg_get_name(info), alpm_pkg_get_version(info)); + if(ppath && strcmp(ppath, rpath) == 0) { + printf(_("%s is owned by %s %s\n"), filename, alpm_pkg_get_name(info), alpm_pkg_get_version(info)); gotcha = 1; - break; } + + free(ppath); } } if(!gotcha) { ERR(NL, _("No package owns %s\n"), filename); } + + free(rpath); } int pacman_query(alpm_list_t *targets) |