Skip to content

Commit d2d15fe

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

5 files changed

Lines changed: 32 additions & 20 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
@@ -56,6 +56,7 @@ usage(bool fail)
5656
" specified multiple times\n"
5757
" --regex Use Extended Regular Expressions to match\n"
5858
" --fulldeptree Full dependency tree for -x/--deps\n"
59+
" --long Show permissions, ownership, and size for -f/--files\n"
5960
" -r, --rootdir <dir> Full path to rootdir\n"
6061
" -V, --version Show XBPS version\n"
6162
" -v, --verbose Verbose messages\n"
@@ -124,6 +125,7 @@ main(int argc, char **argv)
124125
{ "verbose", no_argument, NULL, 'v' },
125126
{ "files", required_argument, NULL, 'f' },
126127
{ "format", required_argument, NULL, 'F' },
128+
{ "long", no_argument, NULL, 4 },
127129
{ "deps", required_argument, NULL, 'x' },
128130
{ "revdeps", required_argument, NULL, 'X' },
129131
{ "regex", no_argument, NULL, 0 },
@@ -136,14 +138,14 @@ main(int argc, char **argv)
136138
int c, flags, rv;
137139
bool list_pkgs, list_repos, orphans, own, list_repolock;
138140
bool list_manual, list_hold, show_prop, show_files, show_deps, show_rdeps;
139-
bool show, pkg_search, regex, repo_mode, opmode, fulldeptree;
141+
bool show, pkg_search, regex, repo_mode, opmode, fulldeptree, long_listing;
140142

141143
rootdir = cachedir = confdir = props = pkg = catfile = format = NULL;
142144
flags = rv = c = 0;
143145
list_pkgs = list_repos = list_hold = orphans = pkg_search = own = false;
144146
list_manual = list_repolock = show_prop = show_files = false;
145147
regex = show = show_deps = show_rdeps = fulldeptree = false;
146-
repo_mode = opmode = false;
148+
repo_mode = opmode = long_listing = false;
147149

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

@@ -240,6 +242,9 @@ main(int argc, char **argv)
240242
case 3:
241243
list_repolock = opmode = true;
242244
break;
245+
case 4:
246+
long_listing = true;
247+
break;
243248
case '?':
244249
default:
245250
usage(true);
@@ -329,9 +334,9 @@ main(int argc, char **argv)
329334
} else if (show_files) {
330335
/* show-files mode */
331336
if (repo_mode)
332-
rv = repo_show_pkg_files(&xh, pkg);
337+
rv = repo_show_pkg_files(&xh, pkg, long_listing);
333338
else
334-
rv = show_pkg_files_from_metadir(&xh, pkg);
339+
rv = show_pkg_files_from_metadir(&xh, pkg, long_listing);
335340

336341
} else if (show_deps) {
337342
/* show-deps mode */

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ show_pkg_info(xbps_dictionary_t dict)
187187
}
188188

189189
int
190-
show_pkg_files(xbps_dictionary_t filesd)
190+
show_pkg_files(xbps_dictionary_t filesd, bool long_listing)
191191
{
192192
xbps_array_t array, allkeys;
193193
xbps_object_t obj;
194194
xbps_dictionary_keysym_t ksym;
195-
const char *keyname = NULL, *file = NULL;
195+
const char *keyname = NULL, *fmt = NULL;
196196

197197
if (xbps_object_type(filesd) != XBPS_TYPE_DICTIONARY)
198198
return EINVAL;
@@ -214,13 +214,15 @@ show_pkg_files(xbps_dictionary_t filesd)
214214
obj = xbps_array_get(array, x);
215215
if (xbps_object_type(obj) != XBPS_TYPE_DICTIONARY)
216216
continue;
217-
xbps_dictionary_get_cstring_nocopy(obj, "file", &file);
218-
printf("%s", file);
219-
if (xbps_dictionary_get_cstring_nocopy(obj,
220-
"target", &file))
221-
printf(" -> %s", file);
222-
223-
printf("\n");
217+
if (long_listing)
218+
fmt = "{mode!strmode} {user} {group} {size!humanize} {file}";
219+
else
220+
fmt = "{file}";
221+
if (xbps_dictionary_get(obj, "target") != NULL)
222+
fmt = xbps_xasprintf("%s -> {target}\n", fmt);
223+
else
224+
fmt = xbps_xasprintf("%s\n", fmt);
225+
xbps_fmts_dictionary(fmt, obj, stdout);
224226
}
225227
}
226228
xbps_object_release(allkeys);
@@ -248,7 +250,7 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
248250
}
249251

250252
int
251-
show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg)
253+
show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg, bool long_listing)
252254
{
253255
xbps_dictionary_t d;
254256
int rv = 0;
@@ -257,7 +259,7 @@ show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg)
257259
if (d == NULL)
258260
return ENOENT;
259261

260-
rv = show_pkg_files(d);
262+
rv = show_pkg_files(d, long_listing);
261263

262264
return rv;
263265
}
@@ -324,7 +326,7 @@ repo_cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
324326
}
325327

326328
int
327-
repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
329+
repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg, bool long_listing)
328330
{
329331
xbps_dictionary_t pkgd;
330332
int rv;
@@ -337,7 +339,7 @@ repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
337339
return errno;
338340
}
339341

340-
rv = show_pkg_files(pkgd);
342+
rv = show_pkg_files(pkgd, long_listing);
341343
xbps_object_release(pkgd);
342344
return rv;
343345
}

bin/xbps-query/xbps-query.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ modes.
134134
Prints a full dependency tree in the
135135
.Sy show dependencies
136136
mode.
137+
.It Fl -long
138+
Prints permissions, ownership, and filesize in the
139+
.Sy files
140+
mode.
137141
.It Fl r, Fl -rootdir Ar dir
138142
Specifies a full path for the target root directory.
139143
.It Fl v, Fl -verbose

data/_xbps

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

0 commit comments

Comments
 (0)