summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2014-10-06 14:45:10 +0300
committerTimo Teräs <timo.teras@iki.fi>2014-10-06 14:45:10 +0300
commit6ea922cc870c27c25fb377d75a570de676175e5e (patch)
tree07ebbc93f2e0079f9e14046f54e8aff381327045
parentf911f7043becd562d2adfafcb26e192023b9c73f (diff)
downloadapk-tools-6ea922cc870c27c25fb377d75a570de676175e5e.tar.gz
apk-tools-6ea922cc870c27c25fb377d75a570de676175e5e.tar.bz2
apk-tools-6ea922cc870c27c25fb377d75a570de676175e5e.tar.xz
apk-tools-6ea922cc870c27c25fb377d75a570de676175e5e.zip
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.
-rw-r--r--src/info.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/info.c b/src/info.c
index c5b987b..9af28f4 100644
--- a/src/info.c
+++ b/src/info.c
@@ -11,6 +11,7 @@
#include <stdio.h>
#include <unistd.h>
+#include <limits.h>
#include "apk_defines.h"
#include "apk_applet.h"
#include "apk_package.h"
@@ -95,13 +96,24 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
struct apk_dependency_array *deps;
struct apk_dependency dep;
struct apk_ostream *os;
- char **parg;
+ const char *via;
+ char **parg, buf[PATH_MAX];
int errors = 0;
+ ssize_t r;
apk_dependency_array_init(&deps);
foreach_array_item(parg, args) {
+ via = "";
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) {
apk_error("%s: Could not find owner package", *parg);
errors++;
continue;
@@ -115,8 +127,8 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
};
apk_deps_add(&deps, &dep);
} else {
- printf("%s is owned by " PKG_VER_FMT "\n",
- *parg, PKG_VER_PRINTF(pkg));
+ printf("%s %sis owned by " PKG_VER_FMT "\n",
+ *parg, via, PKG_VER_PRINTF(pkg));
}
}
if (apk_verbosity < 1 && deps->num != 0) {