32#include "xbps_api_impl.h"
35xbps_register_pkg(
struct xbps_handle *xhp, xbps_dictionary_t pkgrd)
37 xbps_array_t replaces;
38 xbps_dictionary_t pkgd;
41 const char *pkgver, *pkgname;
42 char sha256[XBPS_SHA256_SIZE], outstr[64], *buf;
45 assert(xbps_object_type(pkgrd) == XBPS_TYPE_DICTIONARY);
47 xbps_dictionary_make_immutable(pkgrd);
48 if ((pkgd = xbps_dictionary_copy_mutable(pkgrd)) == NULL) {
52 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
53 xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &pkgname);
55 if (xhp->
flags & XBPS_FLAG_INSTALL_REPRO) {
61 xbps_dictionary_remove(pkgd,
"repository");
67 if ((tmp = localtime_r(&t, &tm)) == NULL) {
68 xbps_dbg_printf(
"%s: localtime_r failed: %s\n",
69 pkgver, strerror(errno));
73 if (strftime(outstr,
sizeof(outstr)-1,
"%F %R %Z", tmp) == 0) {
74 xbps_dbg_printf(
"%s: strftime failed: %s\n",
75 pkgver, strerror(errno));
79 if (!xbps_dictionary_set_cstring(pkgd,
"install-date", outstr)) {
80 xbps_dbg_printf(
"%s: install-date set failed!\n", pkgver);
90 xbps_dictionary_set_cstring(pkgd,
"metafile-sha256", sha256);
96 if ((replaces = xbps_dictionary_get(pkgd,
"replaces"))) {
100 if (!xbps_array_count(replaces))
101 xbps_dictionary_remove(pkgd,
"replaces");
106 xbps_dictionary_remove(pkgd,
"download");
107 xbps_dictionary_remove(pkgd,
"remove-and-update");
108 xbps_dictionary_remove(pkgd,
"transaction");
109 xbps_dictionary_remove(pkgd,
"skip-obsoletes");
110 xbps_dictionary_remove(pkgd,
"pkgname");
111 xbps_dictionary_remove(pkgd,
"version");
113 if (!xbps_dictionary_set(xhp->
pkgdb, pkgname, pkgd)) {
114 xbps_dbg_printf(
"%s: failed to set pkgd for %s\n", __func__, pkgver);
117 xbps_object_release(pkgd);
char metadir[XBPS_MAXPATH+sizeof(XBPS_META_PATH)]
Generic XBPS structure handler for initialization.
char * xbps_xasprintf(const char *fmt,...) __attribute__((format(printf
bool xbps_file_sha256(char *dst, size_t len, const char *file)
bool xbps_remove_string_from_array(xbps_array_t array, const char *str)