[PATCH v2 1/2] pacman/query.c: in query_fileowner, make is_dir an int

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH v2 1/2] pacman/query.c: in query_fileowner, make is_dir an int

Ivy Foster-2
From: Ivy Foster <[hidden email]>

S_ISDIR is int and "returns non-zero" if the file is a directory.

Signed-off-by: Ivy Foster <[hidden email]>
---
I know this is super trivial; I just noticed it while working on the
following patch, and didn't want to make an unrelated change in it.

 src/pacman/query.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/pacman/query.c b/src/pacman/query.c
index 4a37a338..91ca78a7 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -158,8 +158,9 @@ static int query_fileowner(alpm_list_t *targets)
  char rpath[PATH_MAX], *rel_path;
  struct stat buf;
  alpm_list_t *i;
- size_t len, is_dir;
+ size_t len;
  unsigned int found = 0;
+ int is_dir;
 
  if((filename = strdup(t->data)) == NULL) {
  goto targcleanup;
--
2.16.1
Reply | Threaded
Open this post in threaded view
|

[PATCH v2 2/2] src/pacman/query.c: do not exit -Qo with error if file does not exist

Ivy Foster-2
From: Ivy Foster <[hidden email]>

Query operations act on the local db, not the filesystem. Also, a
valid use case for -Qo is to discover what package owns a deleted file
so it can be reinstalled.

Closes FS#55856.

Signed-off-by: Ivy Foster <[hidden email]>
---
This version of the patch handles both missing directories and the
missing file's parent directory *also* being missing.

 src/pacman/query.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/src/pacman/query.c b/src/pacman/query.c
index 91ca78a7..e4104171 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -160,7 +160,7 @@ static int query_fileowner(alpm_list_t *targets)
  alpm_list_t *i;
  size_t len;
  unsigned int found = 0;
- int is_dir;
+ int is_dir, is_missing = 0;
 
  if((filename = strdup(t->data)) == NULL) {
  goto targcleanup;
@@ -177,25 +177,14 @@ static int query_fileowner(alpm_list_t *targets)
  filename[len--] = '\0';
  }
 
- if(lstat(filename, &buf) == -1) {
- /* if it is not a path but a program name, then check in PATH */
- if(strchr(filename, '/') == NULL) {
- if(search_path(&filename, &buf) == -1) {
- pm_printf(ALPM_LOG_ERROR, _("failed to find '%s' in PATH: %s\n"),
- filename, strerror(errno));
- goto targcleanup;
- }
- } else {
- pm_printf(ALPM_LOG_ERROR, _("failed to read file '%s': %s\n"),
- filename, strerror(errno));
- goto targcleanup;
- }
+ /* if it is not a path but a program name, then check in PATH */
+ if((lstat(filename, &buf) == -1) && (strchr(filename, '/') == NULL)) {
+ search_path(&filename, &buf);
  }
 
  if(!lrealpath(filename, rpath)) {
- pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s\n"),
- filename, strerror(errno));
- goto targcleanup;
+ strncpy(rpath, filename, PATH_MAX);
+ is_missing = 1;
  }
 
  if(strncmp(rpath, root, rootlen) != 0) {
@@ -215,7 +204,7 @@ static int query_fileowner(alpm_list_t *targets)
  strcat(rpath + rlen, "/");
  }
 
- for(i = packages; i && (!found || is_dir); i = alpm_list_next(i)) {
+ for(i = packages; i && (!found || is_dir || is_missing); i = alpm_list_next(i)) {
  if(alpm_filelist_contains(alpm_pkg_get_files(i->data), rel_path)) {
  print_query_fileowner(rpath, i->data);
  found = 1;
--
2.16.1