@@ -186,13 +186,43 @@ show_pkg_info(xbps_dictionary_t dict)
186
186
xbps_object_release (all_keys );
187
187
}
188
188
189
+ struct file_print_cb {
190
+ xbps_dictionary_t dict ;
191
+ bool islnk ;
192
+ };
193
+
194
+ static int
195
+ file_print_cb (FILE * fp , const struct xbps_fmt * fmt , void * data )
196
+ {
197
+ struct file_print_cb * ctx = data ;
198
+ xbps_object_t obj ;
199
+ if (ctx -> islnk && strcmp (fmt -> var , "mode" ) == 0 ) {
200
+ // symbolic links don't store mode in the metadata, so it would normally display as
201
+ // unknown (?---------). be a bit more like ls -l and print 'l---------' without
202
+ // having to include this data in the plist
203
+ return xbps_fmt_print_number (fmt , 0120000 , fp );
204
+ } else if (strcmp (fmt -> var , "file-target" ) == 0 ) {
205
+ const char * buf , * target ;
206
+ int len ;
207
+ xbps_dictionary_get_cstring_nocopy (ctx -> dict , "file" , & buf );
208
+ if (xbps_dictionary_get_cstring_nocopy (ctx -> dict , "target" , & target )) {
209
+ buf = xbps_xasprintf ("%s -> %s" , buf , target );
210
+ }
211
+ len = strlen (buf );
212
+ return xbps_fmt_print_string (fmt , buf , len , fp );
213
+ }
214
+ obj = xbps_dictionary_get (ctx -> dict , fmt -> var );
215
+ return xbps_fmt_print_object (fmt , obj , fp );
216
+ }
217
+
189
218
int
190
- show_pkg_files (xbps_dictionary_t filesd )
219
+ show_pkg_files (xbps_dictionary_t filesd , const struct xbps_fmt * fmt )
191
220
{
192
221
xbps_array_t array , allkeys ;
193
222
xbps_object_t obj ;
194
223
xbps_dictionary_keysym_t ksym ;
195
- const char * keyname = NULL , * file = NULL ;
224
+ struct file_print_cb ctx = {0 };
225
+ const char * keyname = NULL ;
196
226
197
227
if (xbps_object_type (filesd ) != XBPS_TYPE_DICTIONARY )
198
228
return EINVAL ;
@@ -206,6 +236,8 @@ show_pkg_files(xbps_dictionary_t filesd)
206
236
(strcmp (keyname , "links" )))))
207
237
continue ;
208
238
239
+ ctx .islnk = strcmp (keyname , "links" ) == 0 ;
240
+
209
241
array = xbps_dictionary_get (filesd , keyname );
210
242
if (array == NULL || xbps_array_count (array ) == 0 )
211
243
continue ;
@@ -214,13 +246,9 @@ show_pkg_files(xbps_dictionary_t filesd)
214
246
obj = xbps_array_get (array , x );
215
247
if (xbps_object_type (obj ) != XBPS_TYPE_DICTIONARY )
216
248
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
249
223
- printf ("\n" );
250
+ ctx .dict = obj ;
251
+ xbps_fmt (fmt , & file_print_cb , & ctx , stdout );
224
252
}
225
253
}
226
254
xbps_object_release (allkeys );
@@ -248,7 +276,7 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
248
276
}
249
277
250
278
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 , const struct xbps_fmt * fmt )
252
280
{
253
281
xbps_dictionary_t d ;
254
282
int rv = 0 ;
@@ -257,7 +285,7 @@ show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg)
257
285
if (d == NULL )
258
286
return ENOENT ;
259
287
260
- rv = show_pkg_files (d );
288
+ rv = show_pkg_files (d , fmt );
261
289
262
290
return rv ;
263
291
}
@@ -324,7 +352,7 @@ repo_cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
324
352
}
325
353
326
354
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 , const struct xbps_fmt * fmt )
328
356
{
329
357
xbps_dictionary_t pkgd ;
330
358
int rv ;
@@ -337,7 +365,7 @@ repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
337
365
return errno ;
338
366
}
339
367
340
- rv = show_pkg_files (pkgd );
368
+ rv = show_pkg_files (pkgd , fmt );
341
369
xbps_object_release (pkgd );
342
370
return rv ;
343
371
}
0 commit comments