@@ -186,13 +186,43 @@ show_pkg_info(xbps_dictionary_t dict)
186186 xbps_object_release (all_keys );
187187}
188188
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+
189218int
190- show_pkg_files (xbps_dictionary_t filesd )
219+ show_pkg_files (xbps_dictionary_t filesd , const struct xbps_fmt * fmt )
191220{
192221 xbps_array_t array , allkeys ;
193222 xbps_object_t obj ;
194223 xbps_dictionary_keysym_t ksym ;
195- const char * keyname = NULL , * file = NULL ;
224+ struct file_print_cb ctx = {0 };
225+ const char * keyname = NULL ;
196226
197227 if (xbps_object_type (filesd ) != XBPS_TYPE_DICTIONARY )
198228 return EINVAL ;
@@ -206,6 +236,8 @@ show_pkg_files(xbps_dictionary_t filesd)
206236 (strcmp (keyname , "links" )))))
207237 continue ;
208238
239+ ctx .islnk = strcmp (keyname , "links" ) == 0 ;
240+
209241 array = xbps_dictionary_get (filesd , keyname );
210242 if (array == NULL || xbps_array_count (array ) == 0 )
211243 continue ;
@@ -214,13 +246,9 @@ show_pkg_files(xbps_dictionary_t filesd)
214246 obj = xbps_array_get (array , x );
215247 if (xbps_object_type (obj ) != XBPS_TYPE_DICTIONARY )
216248 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 );
222249
223- printf ("\n" );
250+ ctx .dict = obj ;
251+ xbps_fmt (fmt , & file_print_cb , & ctx , stdout );
224252 }
225253 }
226254 xbps_object_release (allkeys );
@@ -248,7 +276,7 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
248276}
249277
250278int
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 )
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 , fmt );
261289
262290 return rv ;
263291}
@@ -324,7 +352,7 @@ repo_cat_file(struct xbps_handle *xhp, const char *pkg, const char *file)
324352}
325353
326354int
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 )
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 , fmt );
341369 xbps_object_release (pkgd );
342370 return rv ;
343371}
0 commit comments