Commit 6ea922cc authored by Timo Teräs's avatar Timo Teräs

info who-owns: print symlink target owner as a fallback

busybox trigger creates symlinks to itself. This helps user
to see where these come from.
parent f911f704
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h>
#include "apk_defines.h" #include "apk_defines.h"
#include "apk_applet.h" #include "apk_applet.h"
#include "apk_package.h" #include "apk_package.h"
...@@ -95,12 +96,23 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db, ...@@ -95,12 +96,23 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
struct apk_dependency_array *deps; struct apk_dependency_array *deps;
struct apk_dependency dep; struct apk_dependency dep;
struct apk_ostream *os; struct apk_ostream *os;
char **parg; const char *via;
char **parg, buf[PATH_MAX];
int errors = 0; int errors = 0;
ssize_t r;
apk_dependency_array_init(&deps); apk_dependency_array_init(&deps);
foreach_array_item(parg, args) { foreach_array_item(parg, args) {
via = "";
pkg = apk_db_get_file_owner(db, APK_BLOB_STR(*parg)); pkg = apk_db_get_file_owner(db, APK_BLOB_STR(*parg));
if (pkg == NULL) {
r = readlinkat(db->root_fd, *parg, buf, sizeof(buf));
if (r > 0 && r < PATH_MAX && buf[0] == '/') {
pkg = apk_db_get_file_owner(db, APK_BLOB_STR(buf));
via = "symlink target ";
}
}
if (pkg == NULL) { if (pkg == NULL) {
apk_error("%s: Could not find owner package", *parg); apk_error("%s: Could not find owner package", *parg);
errors++; errors++;
...@@ -115,8 +127,8 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db, ...@@ -115,8 +127,8 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
}; };
apk_deps_add(&deps, &dep); apk_deps_add(&deps, &dep);
} else { } else {
printf("%s is owned by " PKG_VER_FMT "\n", printf("%s %sis owned by " PKG_VER_FMT "\n",
*parg, PKG_VER_PRINTF(pkg)); *parg, via, PKG_VER_PRINTF(pkg));
} }
} }
if (apk_verbosity < 1 && deps->num != 0) { if (apk_verbosity < 1 && deps->num != 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment