From 47622eef4dd8fd86a0aa0e3ebdb7b33f7c9d6804 Mon Sep 17 00:00:00 2001 From: Aaron Griffin Date: Wed, 19 Sep 2007 00:21:56 -0500 Subject: 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 --- lib/libalpm/be_files.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'lib/libalpm/be_files.c') diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index 1566fe2d..06891ef5 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -29,6 +29,8 @@ #include #include #include +#include +#include #ifdef CYGWIN #include /* 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" -- cgit v1.2.3-24-g4f1b