32 #include "xbps_api_impl.h"
46 prop_dictionary_t pkgd;
47 prop_array_t provides, rundeps;
51 const char *pkgname, *version, *desc, *pkgver;
54 bool autoinst =
false;
56 assert(prop_object_type(pkgrd) == PROP_TYPE_DICTIONARY);
58 prop_dictionary_get_cstring_nocopy(pkgrd,
"pkgname", &pkgname);
59 prop_dictionary_get_cstring_nocopy(pkgrd,
"version", &version);
60 prop_dictionary_get_cstring_nocopy(pkgrd,
"short_desc", &desc);
61 prop_dictionary_get_cstring_nocopy(pkgrd,
"pkgver", &pkgver);
62 prop_dictionary_get_bool(pkgrd,
"automatic-install", &autoinst);
63 provides = prop_dictionary_get(pkgrd,
"provides");
64 rundeps = prop_dictionary_get(pkgrd,
"run_depends");
66 xbps_set_cb_state(xhp, XBPS_STATE_REGISTER, 0, pkgname, version, NULL);
68 assert(pkgname != NULL);
69 assert(version != NULL);
71 assert(pkgver != NULL);
78 if (!prop_dictionary_set_cstring_nocopy(pkgd,
79 "version", version)) {
80 xbps_dbg_printf(xhp,
"%s: invalid version for %s\n",
85 if (!prop_dictionary_set_cstring_nocopy(pkgd,
87 xbps_dbg_printf(xhp,
"%s: invalid pkgver for %s\n",
92 if (!prop_dictionary_set_cstring_nocopy(pkgd,
93 "short_desc", desc)) {
94 xbps_dbg_printf(xhp,
"%s: invalid short_desc for %s\n",
99 prop_dictionary_get_bool(pkgd,
"automatic-install", &autoinst);
100 if (xhp->
flags & XBPS_FLAG_INSTALL_AUTO)
102 else if (xhp->
flags & XBPS_FLAG_INSTALL_MANUAL)
105 if (!prop_dictionary_set_bool(pkgd,
106 "automatic-install", autoinst)) {
107 xbps_dbg_printf(xhp,
"%s: invalid autoinst for %s\n",
116 if ((tmp = localtime(&t)) == NULL) {
117 xbps_dbg_printf(xhp,
"%s: localtime failed: %s\n",
118 pkgname, strerror(errno));
122 if (strftime(outstr,
sizeof(outstr)-1,
"%F %R %Z", tmp) == 0) {
123 xbps_dbg_printf(xhp,
"%s: strftime failed: %s\n",
124 pkgname, strerror(errno));
128 if (!prop_dictionary_set_cstring(pkgd,
"install-date", outstr)) {
129 xbps_dbg_printf(xhp,
"%s: install-date set failed!\n", pkgname);
134 if (provides && !prop_dictionary_set(pkgd,
"provides", provides)) {
135 xbps_dbg_printf(xhp,
"%s: failed to set provides for %s\n",
141 rundeps = prop_array_create();
143 if (!prop_dictionary_set(pkgd,
"run_depends", rundeps)) {
144 xbps_dbg_printf(xhp,
"%s: failed to set rundeps for %s\n",
156 prop_dictionary_set_cstring(pkgd,
"metafile-sha256", sha256);
162 prop_dictionary_remove(pkgd,
"remove-and-update");
163 prop_dictionary_remove(pkgd,
"transaction");
167 "%s: failed to replace pkgd dict for %s\n",
173 xbps_set_cb_state(xhp, XBPS_STATE_REGISTER_FAIL,
174 rv, pkgname, version,
175 "%s: failed to register package: %s",
176 pkgver, strerror(rv));
188 xbps_set_cb_state(xhp, XBPS_STATE_UNREGISTER, 0, pkgver, NULL, NULL);
191 xbps_set_cb_state(xhp, XBPS_STATE_UNREGISTER_FAIL,
193 "%s: failed to unregister package: %s",
194 pkgver, strerror(errno));