diff options
author | Aaron Griffin <aaronmgriffin@gmail.com> | 2007-09-19 00:21:56 -0500 |
---|---|---|
committer | Aaron Griffin <aaronmgriffin@gmail.com> | 2007-09-28 00:25:57 -0500 |
commit | 47622eef4dd8fd86a0aa0e3ebdb7b33f7c9d6804 (patch) | |
tree | 4fb65c38ad6a8c8fb4577977d78b07b891be3a2f /lib/libalpm/be_files.c | |
parent | 219808714f94788a66a430786c552f60e95b1a01 (diff) | |
download | pacman-47622eef4dd8fd86a0aa0e3ebdb7b33f7c9d6804.tar.xz |
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>
Diffstat (limited to 'lib/libalpm/be_files.c')
-rw-r--r-- | lib/libalpm/be_files.c | 38 |
1 files changed, 30 insertions, 8 deletions
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 <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" |