Skip to content

Commit

Permalink
bin/xbps-query: add --long for -f to show file perms, owner, size
Browse files Browse the repository at this point in the history
  • Loading branch information
classabbyamp committed Mar 14, 2023
1 parent 82c85df commit 6ce61d7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 12 deletions.
6 changes: 3 additions & 3 deletions bin/xbps-query/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ void show_pkg_info(xbps_dictionary_t);
void show_pkg_info_one(xbps_dictionary_t, const char *);
int show_pkg_info_from_metadir(struct xbps_handle *, const char *,
const char *);
int show_pkg_files(xbps_dictionary_t);
int show_pkg_files_from_metadir(struct xbps_handle *, const char *);
int repo_show_pkg_files(struct xbps_handle *, const char *);
int show_pkg_files(xbps_dictionary_t, bool);
int show_pkg_files_from_metadir(struct xbps_handle *, const char *, bool);
int repo_show_pkg_files(struct xbps_handle *, const char *, bool);
int cat_file(struct xbps_handle *, const char *, const char *);
int repo_cat_file(struct xbps_handle *, const char *, const char *);
int repo_show_pkg_info(struct xbps_handle *, const char *, const char *);
Expand Down
13 changes: 9 additions & 4 deletions bin/xbps-query/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ usage(bool fail)
" specified multiple times\n"
" --regex Use Extended Regular Expressions to match\n"
" --fulldeptree Full dependency tree for -x/--deps\n"
" --long Show permissions, ownership, and size for -f/--files\n"
" -r, --rootdir <dir> Full path to rootdir\n"
" -V, --version Show XBPS version\n"
" -v, --verbose Verbose messages\n"
Expand Down Expand Up @@ -100,6 +101,7 @@ main(int argc, char **argv)
{ "version", no_argument, NULL, 'V' },
{ "verbose", no_argument, NULL, 'v' },
{ "files", required_argument, NULL, 'f' },
{ "long", no_argument, NULL, 4 },
{ "deps", required_argument, NULL, 'x' },
{ "revdeps", required_argument, NULL, 'X' },
{ "regex", no_argument, NULL, 0 },
Expand All @@ -112,14 +114,14 @@ main(int argc, char **argv)
int c, flags, rv;
bool list_pkgs, list_repos, orphans, own, list_repolock;
bool list_manual, list_hold, show_prop, show_files, show_deps, show_rdeps;
bool show, pkg_search, regex, repo_mode, opmode, fulldeptree;
bool show, pkg_search, regex, repo_mode, opmode, fulldeptree, long_listing;

rootdir = cachedir = confdir = props = pkg = catfile = NULL;
flags = rv = c = 0;
list_pkgs = list_repos = list_hold = orphans = pkg_search = own = false;
list_manual = list_repolock = show_prop = show_files = false;
regex = show = show_deps = show_rdeps = fulldeptree = false;
repo_mode = opmode = false;
repo_mode = opmode = long_listing = false;

memset(&xh, 0, sizeof(xh));

Expand Down Expand Up @@ -213,6 +215,9 @@ main(int argc, char **argv)
case 3:
list_repolock = opmode = true;
break;
case 4:
long_listing = true;
break;
case '?':
default:
usage(true);
Expand Down Expand Up @@ -302,9 +307,9 @@ main(int argc, char **argv)
} else if (show_files) {
/* show-files mode */
if (repo_mode)
rv = repo_show_pkg_files(&xh, pkg);
rv = repo_show_pkg_files(&xh, pkg, long_listing);
else
rv = show_pkg_files_from_metadir(&xh, pkg);
rv = show_pkg_files_from_metadir(&xh, pkg, long_listing);

} else if (show_deps) {
/* show-deps mode */
Expand Down
38 changes: 33 additions & 5 deletions bin/xbps-query/show-info-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <libgen.h>
#include <fnmatch.h>
#include <assert.h>
#include <pwd.h>
#include <grp.h>

#include <xbps.h>
#include "defs.h"
Expand Down Expand Up @@ -187,7 +189,7 @@ show_pkg_info(xbps_dictionary_t dict)
}

int
show_pkg_files(xbps_dictionary_t filesd)
show_pkg_files(xbps_dictionary_t filesd, bool long_listing)
{
xbps_array_t array, allkeys;
xbps_object_t obj;
Expand All @@ -214,6 +216,32 @@ show_pkg_files(xbps_dictionary_t filesd)
obj = xbps_array_get(array, x);
if (xbps_object_type(obj) != XBPS_TYPE_DICTIONARY)
continue;
if (long_listing) {
// TODO: do with xbps_fmt_* api
// mode_t mode = 0;
// uint64_t size = 0;
// char hmode[10], *owner = NULL, *group = NULL;
// if (xbps_dictionary_get_uint32(obj, "mode", &mode)) {
// xbps_strmode(mode, hmode);
// printf("%s\t", hmode);
// } else {
// printf("?\t");
// }
// if (xbps_dictionary_get_cstring_nocopy(obj, "owner", owner))
// printf("%s\t", owner);
// else
// printf("?\t");

// if (xbps_dictionary_get_cstring_nocopy(obj, "group", group))
// printf("%s\t", group);
// else
// printf("?\t");

// if (xbps_dictionary_get_uint64(obj, "size", &size))
// printf("%lu\t", size);
// else
// printf("?\t");
}
xbps_dictionary_get_cstring_nocopy(obj, "file", &file);
printf("%s", file);
if (xbps_dictionary_get_cstring_nocopy(obj,
Expand Down Expand Up @@ -248,7 +276,7 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
}

int
show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg)
show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg, bool long_listing)
{
xbps_dictionary_t d;
int rv = 0;
Expand All @@ -257,7 +285,7 @@ show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg)
if (d == NULL)
return ENOENT;

rv = show_pkg_files(d);
rv = show_pkg_files(d, long_listing);

return rv;
}
Expand Down Expand Up @@ -324,7 +352,7 @@ repo_cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
}

int
repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg, bool long_listing)
{
xbps_dictionary_t pkgd;
int rv;
Expand All @@ -337,7 +365,7 @@ repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
return errno;
}

rv = show_pkg_files(pkgd);
rv = show_pkg_files(pkgd, long_listing);
xbps_object_release(pkgd);
return rv;
}
4 changes: 4 additions & 0 deletions bin/xbps-query/xbps-query.1
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ modes.
Prints a full dependency tree in the
.Sy show dependencies
mode.
.It Fl -long
Prints permissions, ownership, and filesize in the
.Sy files
mode.
.It Fl r, Fl -rootdir Ar dir
Specifies a full path for the target root directory.
.It Fl v, Fl -verbose
Expand Down
1 change: 1 addition & 0 deletions data/_xbps
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ _xbps_query() {
{-p,--property=-}'[Show properties]:property:($_xbps_properties)' \
--regex'[Use Extended Regular Expressions to match]' \
--fulldeptree'[Full dependency tree for -x/--deps]' \
--long'[Show permissions, ownership, and size for -f/--files]' \
{-R,--repository}'[Enable repository mode]' \
'*'--repository=-'[Add repository to the top of the list]:repository url:_files -/' \
- '(mode)' \
Expand Down

0 comments on commit 6ce61d7

Please sign in to comment.