@@ -64,22 +64,23 @@ binpkg_parse(char *buf, size_t bufsz, const char *path, const char **pkgver, con
6464 return 0 ;
6565}
6666
67+ struct cleaner_data {
68+ bool dry ;
69+ bool uninstalled ;
70+ };
71+
6772static int
6873cleaner_cb (struct xbps_handle * xhp , xbps_object_t obj ,
6974 const char * key UNUSED , void * arg ,
7075 bool * done UNUSED )
7176{
7277 char buf [PATH_MAX ];
73- xbps_dictionary_t repo_pkgd ;
78+ xbps_dictionary_t pkgd ;
7479 const char * binpkg , * rsha256 ;
7580 const char * binpkgver , * binpkgarch ;
76- bool drun = false ;
81+ struct cleaner_data * data = arg ;
7782 int r ;
7883
79- /* Extract drun (dry-run) flag from arg*/
80- if (arg != NULL )
81- drun = * (bool * )arg ;
82-
8384 binpkg = xbps_string_cstring_nocopy (obj );
8485 r = binpkg_parse (buf , sizeof (buf ), binpkg , & binpkgver , & binpkgarch );
8586 if (r < 0 ) {
@@ -96,9 +97,13 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
9697 * Remove binary pkg if it's not registered in any repository
9798 * or if hash doesn't match.
9899 */
99- repo_pkgd = xbps_rpool_get_pkg (xhp , binpkgver );
100- if (repo_pkgd ) {
101- xbps_dictionary_get_cstring_nocopy (repo_pkgd ,
100+ if (data -> uninstalled ) {
101+ pkgd = xbps_pkgdb_get_pkg (xhp , binpkgver );
102+ } else {
103+ pkgd = xbps_rpool_get_pkg (xhp , binpkgver );
104+ }
105+ if (pkgd ) {
106+ xbps_dictionary_get_cstring_nocopy (pkgd ,
102107 "filename-sha256" , & rsha256 );
103108 r = xbps_file_sha256_check (binpkg , rsha256 );
104109 if (r == 0 ) {
@@ -111,13 +116,13 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
111116 }
112117 }
113118 snprintf (buf , sizeof (buf ), "%s.sig" , binpkg );
114- if (!drun && unlink (binpkg ) == -1 ) {
119+ if (!data -> dry && unlink (binpkg ) == -1 ) {
115120 xbps_error_printf ("Failed to remove `%s': %s\n" ,
116121 binpkg , strerror (errno ));
117122 } else {
118123 printf ("Removed %s from cachedir (obsolete)\n" , binpkg );
119124 }
120- if (!drun && unlink (buf ) == -1 && errno != ENOENT ) {
125+ if (!data -> dry && unlink (buf ) == -1 && errno != ENOENT ) {
121126 xbps_error_printf ("Failed to remove `%s': %s\n" ,
122127 buf , strerror (errno ));
123128 }
@@ -126,7 +131,7 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
126131}
127132
128133int
129- clean_cachedir (struct xbps_handle * xhp , bool drun )
134+ clean_cachedir (struct xbps_handle * xhp , bool uninstalled , bool drun )
130135{
131136 xbps_array_t array = NULL ;
132137 DIR * dirp ;
@@ -158,7 +163,11 @@ clean_cachedir(struct xbps_handle *xhp, bool drun)
158163 (void )closedir (dirp );
159164
160165 if (xbps_array_count (array )) {
161- rv = xbps_array_foreach_cb_multi (xhp , array , NULL , cleaner_cb , (void * )& drun );
166+ struct cleaner_data data = {
167+ .dry = drun ,
168+ .uninstalled = uninstalled ,
169+ };
170+ rv = xbps_array_foreach_cb_multi (xhp , array , NULL , cleaner_cb , (void * )& data );
162171 xbps_object_release (array );
163172 }
164173 return rv ;
0 commit comments