5555static int
5656trans_find_pkg (struct xbps_handle * xhp , const char * pkg , bool force )
5757{
58- xbps_dictionary_t pkg_pkgdb = NULL , pkg_repod = NULL ;
58+ xbps_dictionary_t pkg_pkgdb = NULL , pkg_repod = NULL , vpkg_pkgdb = NULL ;
5959 xbps_object_t obj ;
6060 xbps_array_t pkgs ;
6161 pkg_state_t state = 0 ;
@@ -72,32 +72,37 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
7272 */
7373 if (xbps_pkg_name (buf , sizeof (buf ), pkg )) {
7474 pkg_pkgdb = xbps_pkgdb_get_pkg (xhp , buf );
75+ if (!pkg_pkgdb )
76+ vpkg_pkgdb = xbps_pkgdb_get_virtualpkg (xhp , buf );
7577 } else {
7678 pkg_pkgdb = xbps_pkgdb_get_pkg (xhp , pkg );
79+ if (!pkg_pkgdb )
80+ vpkg_pkgdb = xbps_pkgdb_get_virtualpkg (xhp , pkg );
7781 }
7882
7983 if (xhp -> flags & XBPS_FLAG_DOWNLOAD_ONLY ) {
8084 pkg_pkgdb = NULL ;
8185 ttype = XBPS_TRANS_DOWNLOAD ;
8286 }
8387
84- /*
85- * Find out if the pkg has been found in repository pool.
86- */
87- if (pkg_pkgdb == NULL ) {
88- /* pkg not installed, perform installation */
89- ttype = XBPS_TRANS_INSTALL ;
90- if (((pkg_repod = xbps_rpool_get_pkg (xhp , pkg )) == NULL ) &&
91- ((pkg_repod = xbps_rpool_get_virtualpkg (xhp , pkg )) == NULL )) {
92- /* not found */
93- return ENOENT ;
94- }
95- } else {
88+ if (vpkg_pkgdb ) {
89+ // virtual package installed, if there is no real package in
90+ // the rpool, we are keeping the virtual package.
91+ pkg_repod = xbps_rpool_get_pkg (xhp , pkg );
92+ if (!pkg_repod )
93+ pkg_pkgdb = vpkg_pkgdb ;
94+ }
95+ if (pkg_pkgdb ) {
96+ // package already installed
9697 if (force ) {
9798 ttype = XBPS_TRANS_REINSTALL ;
9899 } else {
99100 ttype = XBPS_TRANS_UPDATE ;
100101 }
102+ if (!xbps_dictionary_get_cstring_nocopy (pkg_pkgdb , "pkgname" , & pkgname )) {
103+ xbps_error_printf ("missing `pkgname` property\n" );
104+ return EINVAL ;
105+ }
101106 if (xbps_dictionary_get (pkg_pkgdb , "repolock" )) {
102107 struct xbps_repo * repo ;
103108 /* find update from repo */
@@ -107,15 +112,21 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
107112 /* not found */
108113 return ENOENT ;
109114 }
110- pkg_repod = xbps_repo_get_pkg (repo , pkg );
115+ pkg_repod = xbps_repo_get_pkg (repo , pkgname );
111116 } else {
112117 /* find update from rpool */
113- pkg_repod = xbps_rpool_get_pkg (xhp , pkg );
114- }
115- if (pkg_repod == NULL ) {
116- /* not found */
117- return ENOENT ;
118+ pkg_repod = xbps_rpool_get_pkg (xhp , pkgname );
118119 }
120+ } else {
121+ ttype = XBPS_TRANS_INSTALL ;
122+ pkg_repod = xbps_rpool_get_pkg (xhp , pkg );
123+ if (!pkg_repod )
124+ pkg_repod = xbps_rpool_get_virtualpkg (xhp , pkg );
125+ }
126+
127+ if (!pkg_repod ) {
128+ /* not found */
129+ return ENOENT ;
119130 }
120131
121132 xbps_dictionary_get_cstring_nocopy (pkg_repod , "pkgver" , & repopkgver );
@@ -179,6 +190,7 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
179190 }
180191
181192 if (!xbps_dictionary_get_cstring_nocopy (pkg_repod , "pkgname" , & pkgname )) {
193+ xbps_error_printf ("missing `pkgname` property\n" );
182194 return EINVAL ;
183195 }
184196 /*
0 commit comments