Skip to content

Commit 3775688

Browse files
committed
bin/xbps-query: add --long for -f to show file perms, owner, size
1 parent 1436551 commit 3775688

5 files changed

Lines changed: 56 additions & 12 deletions

File tree

bin/xbps-query/defs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ void show_pkg_info(xbps_dictionary_t);
3939
void show_pkg_info_one(xbps_dictionary_t, const char *);
4040
int show_pkg_info_from_metadir(struct xbps_handle *, const char *,
4141
const char *);
42-
int show_pkg_files(xbps_dictionary_t);
43-
int show_pkg_files_from_metadir(struct xbps_handle *, const char *);
44-
int repo_show_pkg_files(struct xbps_handle *, const char *);
42+
int show_pkg_files(xbps_dictionary_t, bool);
43+
int show_pkg_files_from_metadir(struct xbps_handle *, const char *, bool);
44+
int repo_show_pkg_files(struct xbps_handle *, const char *, bool);
4545
int cat_file(struct xbps_handle *, const char *, const char *);
4646
int repo_cat_file(struct xbps_handle *, const char *, const char *);
4747
int repo_show_pkg_info(struct xbps_handle *, const char *, const char *);

bin/xbps-query/main.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ usage(bool fail)
5353
" specified multiple times\n"
5454
" --regex Use Extended Regular Expressions to match\n"
5555
" --fulldeptree Full dependency tree for -x/--deps\n"
56+
" --long Show permissions, ownership, and size for -f/--files\n"
5657
" -r, --rootdir <dir> Full path to rootdir\n"
5758
" -V, --version Show XBPS version\n"
5859
" -v, --verbose Verbose messages\n"
@@ -100,6 +101,7 @@ main(int argc, char **argv)
100101
{ "version", no_argument, NULL, 'V' },
101102
{ "verbose", no_argument, NULL, 'v' },
102103
{ "files", required_argument, NULL, 'f' },
104+
{ "long", no_argument, NULL, 4 },
103105
{ "deps", required_argument, NULL, 'x' },
104106
{ "revdeps", required_argument, NULL, 'X' },
105107
{ "regex", no_argument, NULL, 0 },
@@ -112,14 +114,14 @@ main(int argc, char **argv)
112114
int c, flags, rv;
113115
bool list_pkgs, list_repos, orphans, own, list_repolock;
114116
bool list_manual, list_hold, show_prop, show_files, show_deps, show_rdeps;
115-
bool show, pkg_search, regex, repo_mode, opmode, fulldeptree;
117+
bool show, pkg_search, regex, repo_mode, opmode, fulldeptree, long_listing;
116118

117119
rootdir = cachedir = confdir = props = pkg = catfile = NULL;
118120
flags = rv = c = 0;
119121
list_pkgs = list_repos = list_hold = orphans = pkg_search = own = false;
120122
list_manual = list_repolock = show_prop = show_files = false;
121123
regex = show = show_deps = show_rdeps = fulldeptree = false;
122-
repo_mode = opmode = false;
124+
repo_mode = opmode = long_listing = false;
123125

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

@@ -213,6 +215,9 @@ main(int argc, char **argv)
213215
case 3:
214216
list_repolock = opmode = true;
215217
break;
218+
case 4:
219+
long_listing = true;
220+
break;
216221
case '?':
217222
default:
218223
usage(true);
@@ -302,9 +307,9 @@ main(int argc, char **argv)
302307
} else if (show_files) {
303308
/* show-files mode */
304309
if (repo_mode)
305-
rv = repo_show_pkg_files(&xh, pkg);
310+
rv = repo_show_pkg_files(&xh, pkg, long_listing);
306311
else
307-
rv = show_pkg_files_from_metadir(&xh, pkg);
312+
rv = show_pkg_files_from_metadir(&xh, pkg, long_listing);
308313

309314
} else if (show_deps) {
310315
/* show-deps mode */

bin/xbps-query/show-info-files.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <libgen.h>
3333
#include <fnmatch.h>
3434
#include <assert.h>
35+
#include <pwd.h>
36+
#include <grp.h>
3537

3638
#include <xbps.h>
3739
#include "defs.h"
@@ -187,7 +189,7 @@ show_pkg_info(xbps_dictionary_t dict)
187189
}
188190

189191
int
190-
show_pkg_files(xbps_dictionary_t filesd)
192+
show_pkg_files(xbps_dictionary_t filesd, bool long_listing)
191193
{
192194
xbps_array_t array, allkeys;
193195
xbps_object_t obj;
@@ -214,6 +216,38 @@ show_pkg_files(xbps_dictionary_t filesd)
214216
obj = xbps_array_get(array, x);
215217
if (xbps_object_type(obj) != XBPS_TYPE_DICTIONARY)
216218
continue;
219+
if (long_listing) {
220+
mode_t mode = 0;
221+
uid_t uid = 0;
222+
gid_t gid = 0;
223+
uint64_t size = 0;
224+
struct passwd *user;
225+
struct group *grp;
226+
char hmode[10];
227+
if (xbps_dictionary_get_uint32(obj, "mode", &mode)) {
228+
xbps_strmode(mode, hmode);
229+
printf("%s\t", hmode);
230+
} else {
231+
printf("?\t");
232+
}
233+
if (xbps_dictionary_get_uint32(obj, "uid", &uid)) {
234+
user = getpwuid(uid);
235+
(user != NULL) ? printf("%s\t", user->pw_name) : printf("%u\t", uid);
236+
} else {
237+
printf("?\t");
238+
}
239+
if (xbps_dictionary_get_uint32(obj, "gid", &gid)) {
240+
grp = getgrgid(gid);
241+
(grp != NULL) ? printf("%s\t", grp->gr_name) : printf("%u\t", gid);
242+
} else {
243+
printf("?\t");
244+
}
245+
if (xbps_dictionary_get_uint64(obj, "size", &size)) {
246+
printf("%lu\t", size);
247+
} else {
248+
printf("?\t");
249+
}
250+
}
217251
xbps_dictionary_get_cstring_nocopy(obj, "file", &file);
218252
printf("%s", file);
219253
if (xbps_dictionary_get_cstring_nocopy(obj,
@@ -248,7 +282,7 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
248282
}
249283

250284
int
251-
show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg)
285+
show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg, bool long_listing)
252286
{
253287
xbps_dictionary_t d;
254288
int rv = 0;
@@ -257,7 +291,7 @@ show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg)
257291
if (d == NULL)
258292
return ENOENT;
259293

260-
rv = show_pkg_files(d);
294+
rv = show_pkg_files(d, long_listing);
261295

262296
return rv;
263297
}
@@ -324,7 +358,7 @@ repo_cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
324358
}
325359

326360
int
327-
repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
361+
repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg, bool long_listing)
328362
{
329363
xbps_dictionary_t pkgd;
330364
int rv;
@@ -337,7 +371,7 @@ repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
337371
return errno;
338372
}
339373

340-
rv = show_pkg_files(pkgd);
374+
rv = show_pkg_files(pkgd, long_listing);
341375
xbps_object_release(pkgd);
342376
return rv;
343377
}

bin/xbps-query/xbps-query.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ modes.
129129
Prints a full dependency tree in the
130130
.Sy show dependencies
131131
mode.
132+
.It Fl -long
133+
Prints permissions, ownership, and filesize in the
134+
.Sy files
135+
mode.
132136
.It Fl r, Fl -rootdir Ar dir
133137
Specifies a full path for the target root directory.
134138
.It Fl v, Fl -verbose

data/_xbps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ _xbps_query() {
154154
{-p,--property=-}'[Show properties]:property:($_xbps_properties)' \
155155
--regex'[Use Extended Regular Expressions to match]' \
156156
--fulldeptree'[Full dependency tree for -x/--deps]' \
157+
--long'[Show permissions, ownership, and size for -f/--files]' \
157158
{-R,--repository}'[Enable repository mode]' \
158159
'*'--repository=-'[Add repository to the top of the list]:repository url:_files -/' \
159160
- '(mode)' \

0 commit comments

Comments
 (0)