Support for localized times in metadata

Packages and DBs now support using the UNIX epoch (seconds since Jan 1, 1970)
for use in builddate and installdate. This will only affect newly built
packages. Old existing packages with the text format are still supported, but
this is deprecated.

In the case of removal of text time support, this code will fail gracefully,
returning the start of the epoch for broken packages.

Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
This commit is contained in:
Aaron Griffin 2007-09-19 00:21:56 -05:00
parent 219808714f
commit 47622eef4d
7 changed files with 49 additions and 27 deletions

View File

@ -809,10 +809,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, int pkg_current, int pkg_count,
_alpm_pkg_update_requiredby(newpkg);
/* make an install date (in UTC) */
time_t t = time(NULL);
strncpy(newpkg->installdate, asctime(gmtime(&t)), PKG_DATE_LEN);
/* remove the extra line feed appended by asctime() */
newpkg->installdate[strlen(newpkg->installdate)-1] = 0;
newpkg->installdate = time(NULL);
_alpm_log(PM_LOG_DEBUG, "updating database\n");
_alpm_log(PM_LOG_DEBUG, "adding database entry '%s'\n", newpkg->name);

View File

@ -192,9 +192,9 @@ const char *alpm_pkg_get_name(pmpkg_t *pkg);
const char *alpm_pkg_get_version(pmpkg_t *pkg);
const char *alpm_pkg_get_desc(pmpkg_t *pkg);
const char *alpm_pkg_get_url(pmpkg_t *pkg);
const char *alpm_pkg_get_builddate(pmpkg_t *pkg);
time_t alpm_pkg_get_builddate(pmpkg_t *pkg);
const char *alpm_pkg_get_buildtype(pmpkg_t *pkg);
const char *alpm_pkg_get_installdate(pmpkg_t *pkg);
time_t alpm_pkg_get_installdate(pmpkg_t *pkg);
const char *alpm_pkg_get_packager(pmpkg_t *pkg);
const char *alpm_pkg_get_md5sum(pmpkg_t *pkg);
const char *alpm_pkg_get_arch(pmpkg_t *pkg);

View File

@ -29,6 +29,8 @@
#include <string.h>
#include <sys/stat.h>
#include <dirent.h>
#include <ctype.h>
#include <time.h>
#ifdef CYGWIN
#include <limits.h> /* PATH_MAX */
#endif
@ -326,15 +328,35 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
}
_alpm_strtrim(info->arch);
} else if(!strcmp(line, "%BUILDDATE%")) {
if(fgets(info->builddate, sizeof(info->builddate), fp) == NULL) {
char tmp[32];
if(fgets(tmp, sizeof(tmp), fp) == NULL) {
goto error;
}
_alpm_strtrim(info->builddate);
_alpm_strtrim(tmp);
char first = tolower(tmp[0]);
if(first > 'a' && first < 'z') {
struct tm tmp_tm = {0}; //initialize to null incase of failure
strptime(tmp, "%a %b %e %H:%M:%S %Y", &tmp_tm);
info->builddate = mktime(&tmp_tm);
} else {
info->builddate = atol(tmp);
}
} else if(!strcmp(line, "%INSTALLDATE%")) {
if(fgets(info->installdate, sizeof(info->installdate), fp) == NULL) {
char tmp[32];
if(fgets(tmp, sizeof(tmp), fp) == NULL) {
goto error;
}
_alpm_strtrim(info->installdate);
_alpm_strtrim(tmp);
char first = tolower(tmp[0]);
if(first > 'a' && first < 'z') {
struct tm tmp_tm = {0}; //initialize to null incase of failure
strptime(tmp, "%a %b %e %H:%M:%S %Y", &tmp_tm);
info->installdate = mktime(&tmp_tm);
} else {
info->installdate = atol(tmp);
}
} else if(!strcmp(line, "%PACKAGER%")) {
if(fgets(info->packager, sizeof(info->packager), fp) == NULL) {
goto error;
@ -546,13 +568,13 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
fprintf(fp, "%%ARCH%%\n"
"%s\n\n", info->arch);
}
if(info->builddate[0]) {
if(info->builddate) {
fprintf(fp, "%%BUILDDATE%%\n"
"%s\n\n", info->builddate);
"%lu\n\n", info->builddate);
}
if(info->installdate[0]) {
if(info->installdate) {
fprintf(fp, "%%INSTALLDATE%%\n"
"%s\n\n", info->installdate);
"%lu\n\n", info->installdate);
}
if(info->packager[0]) {
fprintf(fp, "%%PACKAGER%%\n"

View File

@ -236,13 +236,13 @@ const char SYMEXPORT *alpm_pkg_get_url(pmpkg_t *pkg)
return pkg->url;
}
const char SYMEXPORT *alpm_pkg_get_builddate(pmpkg_t *pkg)
time_t SYMEXPORT alpm_pkg_get_builddate(pmpkg_t *pkg)
{
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));
ASSERT(handle != NULL, return(0));
ASSERT(pkg != NULL, return(0));
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
@ -250,13 +250,13 @@ const char SYMEXPORT *alpm_pkg_get_builddate(pmpkg_t *pkg)
return pkg->builddate;
}
const char SYMEXPORT *alpm_pkg_get_installdate(pmpkg_t *pkg)
time_t SYMEXPORT alpm_pkg_get_installdate(pmpkg_t *pkg)
{
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));
ASSERT(handle != NULL, return(0));
ASSERT(pkg != NULL, return(0));
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
@ -840,7 +840,9 @@ static int parse_descfile(const char *descfile, pmpkg_t *info)
} else if(!strcmp(key, "license")) {
info->licenses = alpm_list_add(info->licenses, strdup(ptr));
} else if(!strcmp(key, "builddate")) {
strncpy(info->builddate, ptr, sizeof(info->builddate));
info->builddate = atol(ptr);
} else if(!strcmp(key, "installdate")) {
info->installdate = atol(ptr);
} else if(!strcmp(key, "packager")) {
strncpy(info->packager, ptr, sizeof(info->packager));
} else if(!strcmp(key, "arch")) {

View File

@ -54,8 +54,8 @@ struct __pmpkg_t {
char version[PKG_VERSION_LEN];
char desc[PKG_DESC_LEN];
char url[PKG_URL_LEN];
char builddate[PKG_DATE_LEN];
char installdate[PKG_DATE_LEN];
time_t builddate;
time_t installdate;
char packager[PKG_PACKAGER_LEN];
char md5sum[PKG_MD5SUM_LEN];
char arch[PKG_ARCH_LEN];

View File

@ -767,7 +767,7 @@ create_package() {
cd "$pkgdir"
msg "$(gettext "Creating package...")"
local builddate=$(LC_ALL= LANG= date -u "+%a %b %e %H:%M:%S %Y")
local builddate=$(date -u "+%s")
if [ "$PACKAGER" != "" ]; then
local packager="$PACKAGER"
else

View File

@ -43,7 +43,8 @@
*/
void dump_pkg_full(pmpkg_t *pkg, int level)
{
const char *bdate, *idate, *reason, *descheader;
const char *reason, *descheader;
time_t bdate, idate;
if(pkg == NULL) {
return;
@ -85,9 +86,9 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
printf(_("Installed Size : %6.2f K\n"), (float)alpm_pkg_get_size(pkg) / 1024.0);
printf(_("Packager : %s\n"), (char *)alpm_pkg_get_packager(pkg));
printf(_("Architecture : %s\n"), (char *)alpm_pkg_get_arch(pkg));
printf(_("Build Date : %s %s\n"), bdate, strlen(bdate) ? "UTC" : "");
printf(_("Build Date : %s"), ctime(&bdate)); /*ctime implicit newline */
if(level > 0) {
printf(_("Install Date : %s %s\n"), idate, strlen(idate) ? "UTC" : "");
printf(_("Install Date : %s"), ctime(&idate)); /*ctime implicit newline */
printf(_("Install Reason : %s\n"), reason);
}
printf(_("Install Script : %s\n"),