Added "install-date" object to pkg's pkgdb dictionary, make xbps-bin(8) print it.

This commit is contained in:
Juan RP 2012-07-11 12:19:39 +02:00
parent d8f1fc978a
commit 2f1e975607
4 changed files with 53 additions and 3 deletions

9
NEWS
View File

@ -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): xbps-0.16.4 (2012-07-10):
* Imported proplib 0.6.1 from http://code.google.com/p/portableproplib. * Imported proplib 0.6.1 from http://code.google.com/p/portableproplib.

View File

@ -39,12 +39,27 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
const char *pkgname, const char *pkgname,
const char *option) 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); d = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGPROPS);
if (d == NULL) if (d == NULL)
return EINVAL; 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) if (option == NULL)
show_pkg_info(d); show_pkg_info(d);
else else

View File

@ -56,8 +56,8 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.5" #define XBPS_PKGINDEX_VERSION "1.5"
#define XBPS_API_VERSION "20120710" #define XBPS_API_VERSION "20120711"
#define XBPS_VERSION "0.16.4" #define XBPS_VERSION "0.16.5"
/** /**
* @def XBPS_RELVER * @def XBPS_RELVER

View File

@ -27,6 +27,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <time.h>
#include "xbps_api_impl.h" #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_dictionary_t pkgd = NULL;
prop_array_t provides, reqby; prop_array_t provides, reqby;
char outstr[64];
time_t t;
struct tm *tmp;
const char *pkgname, *version, *desc, *pkgver; const char *pkgname, *version, *desc, *pkgver;
int rv = 0; int rv = 0;
bool autoinst = false; bool autoinst = false;
@ -110,6 +114,28 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
rv = EINVAL; rv = EINVAL;
goto out; 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 (provides) {
if (!prop_dictionary_set(pkgd, "provides", provides)) { if (!prop_dictionary_set(pkgd, "provides", provides)) {
xbps_dbg_printf(xhp, xbps_dbg_printf(xhp,