Skip to content

Commit 6ce61d7

Browse files
committed
bin/xbps-query: add --long for -f to show file perms, owner, size
1 parent 82c85df commit 6ce61d7

File tree

5 files changed

+50
-12
lines changed

5 files changed

+50
-12
lines changed

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: 33 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,32 @@ 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+
// TODO: do with xbps_fmt_* api
221+
// mode_t mode = 0;
222+
// uint64_t size = 0;
223+
// char hmode[10], *owner = NULL, *group = NULL;
224+
// if (xbps_dictionary_get_uint32(obj, "mode", &mode)) {
225+
// xbps_strmode(mode, hmode);
226+
// printf("%s\t", hmode);
227+
// } else {
228+
// printf("?\t");
229+
// }
230+
// if (xbps_dictionary_get_cstring_nocopy(obj, "owner", owner))
231+
// printf("%s\t", owner);
232+
// else
233+
// printf("?\t");
234+
235+
// if (xbps_dictionary_get_cstring_nocopy(obj, "group", group))
236+
// printf("%s\t", group);
237+
// else
238+
// printf("?\t");
239+
240+
// if (xbps_dictionary_get_uint64(obj, "size", &size))
241+
// printf("%lu\t", size);
242+
// else
243+
// printf("?\t");
244+
}
217245
xbps_dictionary_get_cstring_nocopy(obj, "file", &file);
218246
printf("%s", file);
219247
if (xbps_dictionary_get_cstring_nocopy(obj,
@@ -248,7 +276,7 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
248276
}
249277

250278
int
251-
show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg)
279+
show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg, bool long_listing)
252280
{
253281
xbps_dictionary_t d;
254282
int rv = 0;
@@ -257,7 +285,7 @@ show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg)
257285
if (d == NULL)
258286
return ENOENT;
259287

260-
rv = show_pkg_files(d);
288+
rv = show_pkg_files(d, long_listing);
261289

262290
return rv;
263291
}
@@ -324,7 +352,7 @@ repo_cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
324352
}
325353

326354
int
327-
repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
355+
repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg, bool long_listing)
328356
{
329357
xbps_dictionary_t pkgd;
330358
int rv;
@@ -337,7 +365,7 @@ repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
337365
return errno;
338366
}
339367

340-
rv = show_pkg_files(pkgd);
368+
rv = show_pkg_files(pkgd, long_listing);
341369
xbps_object_release(pkgd);
342370
return rv;
343371
}

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)