32
32
#include <libgen.h>
33
33
#include <fnmatch.h>
34
34
#include <assert.h>
35
+ #include <pwd.h>
36
+ #include <grp.h>
35
37
36
38
#include <xbps.h>
37
39
#include "defs.h"
38
40
39
41
#define _BOLD "\033[1m"
40
42
#define _RESET "\033[m"
41
43
44
+ /*
45
+ 1111 111 111 111 111
46
+ ^~~~ ^~~ ^~~ ^~~ ^~~
47
+ | | | | `- other rwx
48
+ | | | `- group rwx
49
+ | | `- user rwx
50
+ | `- suid, sgid, sticky
51
+ `- file type
52
+ */
53
+ static void
54
+ print_mode (const mode_t mode ) {
55
+ char hmode [10 ] = "" ;
56
+ switch (mode & S_IFMT ) {
57
+ case S_IFREG : hmode [0 ] = '-' ; break ;
58
+ case S_IFLNK : hmode [0 ] = 'l' ; break ;
59
+ case S_IFDIR : hmode [0 ] = 'd' ; break ;
60
+ default : hmode [0 ] = '?' ; break ;
61
+ }
62
+ hmode [1 ] = (mode & S_IRUSR ) ? 'r' : '-' ;
63
+ hmode [2 ] = (mode & S_IWUSR ) ? 'w' : '-' ;
64
+ if ((mode & S_ISUID ) && (mode & S_IXUSR )) {
65
+ hmode [3 ] = 's' ;
66
+ } else if (mode & S_ISUID ) {
67
+ hmode [3 ] = 'S' ;
68
+ } else if (mode & S_IXUSR ) {
69
+ hmode [3 ] = 'x' ;
70
+ } else {
71
+ hmode [3 ] = '-' ;
72
+ }
73
+ hmode [4 ] = (mode & S_IRGRP ) ? 'r' : '-' ;
74
+ hmode [5 ] = (mode & S_IWGRP ) ? 'w' : '-' ;
75
+ if ((mode & S_ISGID ) && (mode & S_IXGRP )) {
76
+ hmode [6 ] = 's' ;
77
+ } else if (mode & S_ISGID ) {
78
+ hmode [6 ] = 'S' ;
79
+ } else if (mode & S_IXGRP ) {
80
+ hmode [6 ] = 'x' ;
81
+ } else {
82
+ hmode [6 ] = '-' ;
83
+ }
84
+ hmode [7 ] = (mode & S_IROTH ) ? 'r' : '-' ;
85
+ hmode [8 ] = (mode & S_IWOTH ) ? 'w' : '-' ;
86
+ if ((mode & S_ISVTX ) && (mode & S_IXOTH )) {
87
+ hmode [9 ] = 't' ;
88
+ } else if (mode & S_ISVTX ) {
89
+ hmode [9 ] = 'T' ;
90
+ } else if (mode & S_IXOTH ) {
91
+ hmode [9 ] = 'x' ;
92
+ } else {
93
+ hmode [9 ] = '-' ;
94
+ }
95
+ printf ("%s\t" , hmode );
96
+ }
97
+
42
98
static void
43
99
print_value_obj (const char * keyname , xbps_object_t obj ,
44
100
const char * indent , const char * bold ,
@@ -187,11 +243,17 @@ show_pkg_info(xbps_dictionary_t dict)
187
243
}
188
244
189
245
int
190
- show_pkg_files (xbps_dictionary_t filesd )
246
+ show_pkg_files (xbps_dictionary_t filesd , bool long_listing )
191
247
{
192
248
xbps_array_t array , allkeys ;
193
249
xbps_object_t obj ;
194
250
xbps_dictionary_keysym_t ksym ;
251
+ uint64_t size ;
252
+ uid_t uid ;
253
+ gid_t gid ;
254
+ mode_t mode ;
255
+ struct passwd * user ;
256
+ struct group * grp ;
195
257
const char * keyname = NULL , * file = NULL ;
196
258
197
259
if (xbps_object_type (filesd ) != XBPS_TYPE_DICTIONARY )
@@ -214,6 +276,31 @@ show_pkg_files(xbps_dictionary_t filesd)
214
276
obj = xbps_array_get (array , x );
215
277
if (xbps_object_type (obj ) != XBPS_TYPE_DICTIONARY )
216
278
continue ;
279
+ if (long_listing ) {
280
+ mode = uid = gid = size = 0 ;
281
+ if (xbps_dictionary_get_uint32 (obj , "mode" , & mode )) {
282
+ print_mode (mode );
283
+ } else {
284
+ printf ("?\t" );
285
+ }
286
+ if (xbps_dictionary_get_uint32 (obj , "uid" , & uid )) {
287
+ user = getpwuid (uid );
288
+ (user != NULL ) ? printf ("%s\t" , user -> pw_name ) : printf ("%u\t" , uid );
289
+ } else {
290
+ printf ("?\t" );
291
+ }
292
+ if (xbps_dictionary_get_uint32 (obj , "gid" , & gid )) {
293
+ grp = getgrgid (gid );
294
+ (grp != NULL ) ? printf ("%s\t" , grp -> gr_name ) : printf ("%u\t" , gid );
295
+ } else {
296
+ printf ("?\t" );
297
+ }
298
+ if (xbps_dictionary_get_uint64 (obj , "size" , & size )) {
299
+ printf ("%lu\t" , size );
300
+ } else {
301
+ printf ("?\t" );
302
+ }
303
+ }
217
304
xbps_dictionary_get_cstring_nocopy (obj , "file" , & file );
218
305
printf ("%s" , file );
219
306
if (xbps_dictionary_get_cstring_nocopy (obj ,
@@ -248,7 +335,7 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
248
335
}
249
336
250
337
int
251
- show_pkg_files_from_metadir (struct xbps_handle * xhp , const char * pkg )
338
+ show_pkg_files_from_metadir (struct xbps_handle * xhp , const char * pkg , bool long_listing )
252
339
{
253
340
xbps_dictionary_t d ;
254
341
int rv = 0 ;
@@ -257,7 +344,7 @@ show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg)
257
344
if (d == NULL )
258
345
return ENOENT ;
259
346
260
- rv = show_pkg_files (d );
347
+ rv = show_pkg_files (d , long_listing );
261
348
262
349
return rv ;
263
350
}
@@ -324,7 +411,7 @@ repo_cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
324
411
}
325
412
326
413
int
327
- repo_show_pkg_files (struct xbps_handle * xhp , const char * pkg )
414
+ repo_show_pkg_files (struct xbps_handle * xhp , const char * pkg , bool long_listing )
328
415
{
329
416
xbps_dictionary_t pkgd ;
330
417
int rv ;
@@ -337,7 +424,7 @@ repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
337
424
return errno ;
338
425
}
339
426
340
- rv = show_pkg_files (pkgd );
427
+ rv = show_pkg_files (pkgd , long_listing );
341
428
xbps_object_release (pkgd );
342
429
return rv ;
343
430
}
0 commit comments