From 2f1e975607c530bba40fe2678e62d3eb7e07139e Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 11 Jul 2012 12:19:39 +0200 Subject: [PATCH] Added "install-date" object to pkg's pkgdb dictionary, make xbps-bin(8) print it. --- NEWS | 9 +++++++++ bin/xbps-bin/show-info-files.c | 17 ++++++++++++++++- include/xbps_api.h | 4 ++-- lib/package_register.c | 26 ++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index d540fed1..151ef9c1 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,12 @@ +xbps-0.16.5 (???): + + * libxbps: at package register time a new string object in pkgdb is added + "install-date" that records the package installation date with the following + strftime(3) format: "%F %R %Z". + + * xbps-bin(8): the 'show' target now prints some objects from pkgdb if found: + "install-date" and "automatic-install". + xbps-0.16.4 (2012-07-10): * Imported proplib 0.6.1 from http://code.google.com/p/portableproplib. diff --git a/bin/xbps-bin/show-info-files.c b/bin/xbps-bin/show-info-files.c index 3e18dbe7..a9eaeb40 100644 --- a/bin/xbps-bin/show-info-files.c +++ b/bin/xbps-bin/show-info-files.c @@ -39,12 +39,27 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp, const char *pkgname, const char *option) { - prop_dictionary_t d; + prop_dictionary_t d, pkgdb_d; + const char *instdate; + bool autoinst; d = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGPROPS); if (d == NULL) return EINVAL; + pkgdb_d = xbps_pkgdb_get_pkgd(xhp, pkgname, false); + if (pkgdb_d == NULL) { + prop_object_release(d); + return EINVAL; + } + if (prop_dictionary_get_cstring_nocopy(pkgdb_d, + "install-date", &instdate)) + prop_dictionary_set_cstring_nocopy(d, "install-date", + instdate); + + if (prop_dictionary_get_bool(pkgdb_d, "automatic-install", &autoinst)) + prop_dictionary_set_bool(d, "automatic-install", autoinst); + if (option == NULL) show_pkg_info(d); else diff --git a/include/xbps_api.h b/include/xbps_api.h index f105541a..ea9cfc06 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -56,8 +56,8 @@ */ #define XBPS_PKGINDEX_VERSION "1.5" -#define XBPS_API_VERSION "20120710" -#define XBPS_VERSION "0.16.4" +#define XBPS_API_VERSION "20120711" +#define XBPS_VERSION "0.16.5" /** * @def XBPS_RELVER diff --git a/lib/package_register.c b/lib/package_register.c index 94a46c9f..6ce68d70 100644 --- a/lib/package_register.c +++ b/lib/package_register.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "xbps_api_impl.h" @@ -44,6 +45,9 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush) { prop_dictionary_t pkgd = NULL; prop_array_t provides, reqby; + char outstr[64]; + time_t t; + struct tm *tmp; const char *pkgname, *version, *desc, *pkgver; int rv = 0; bool autoinst = false; @@ -110,6 +114,28 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush) rv = EINVAL; goto out; } + /* + * Set the "install-date" object to know the pkg installation date. + */ + t = time(NULL); + if ((tmp = localtime(&t)) == NULL) { + xbps_dbg_printf(xhp, "%s: localtime failed: %s\n", + pkgname, strerror(errno)); + rv = EINVAL; + goto out; + } + if (strftime(outstr, sizeof(outstr)-1, "%F %R %Z", tmp) == 0) { + xbps_dbg_printf(xhp, "%s: strftime failed: %s\n", + pkgname, strerror(errno)); + rv = EINVAL; + goto out; + } + if (!prop_dictionary_set_cstring(pkgd, "install-date", outstr)) { + xbps_dbg_printf(xhp, "%s: install-date set failed!\n", pkgname); + rv = EINVAL; + goto out; + } + if (provides) { if (!prop_dictionary_set(pkgd, "provides", provides)) { xbps_dbg_printf(xhp,