From f957f17e8fc4f02fded9c58d83d56bdd20e4ff66 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Fri, 22 Oct 2010 15:52:26 +0200 Subject: [PATCH] updateinfoxml: Correctly parse 'issued date' field. --- ext/repo_updateinfoxml.c | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/ext/repo_updateinfoxml.c b/ext/repo_updateinfoxml.c index c2bf69e..406198d 100644 --- a/ext/repo_updateinfoxml.c +++ b/ext/repo_updateinfoxml.c @@ -6,6 +6,7 @@ */ #define _GNU_SOURCE +#define _XOPEN_SOURCE /* glibc2 needs this */ #include #include #include @@ -13,6 +14,7 @@ #include #include #include +#include #include "pool.h" #include "repo.h" @@ -119,9 +121,29 @@ struct parsedata { }; /* + * Convert date strings ("1287746075" or "2010-10-22 13:14:35") + * to timestamp. + */ +static time_t +datestr2timestamp(const char *date) +{ + if (!date) + return 0; + + if (strlen(date) == strspn(date, "0123456789")) + return atoi(date); + + struct tm tm; + memset(&tm, 0, sizeof(tm)); + if (!strptime(date, "%F%T", &tm)) + return 0; + return timegm(&tm); +} + +/* * if we have seen a ... * inside of ... - * + * * * If not, we must insert an empty filename to UPDATE_COLLECTION_FILENAME * at in order to keep all UPDATE_COLLECTION_* arrays in sync @@ -263,11 +285,11 @@ startElement(void *userData, const char *name, const char **atts) else if (!strcmp(*atts, "version")) version = atts[1]; } - + solvable = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo)); pd->datanum = pd->solvable - pool->solvables; - + solvable->vendor = str2id(pool, from, 1); solvable->evr = str2id(pool, version, 1); solvable->arch = ARCH_NOARCH; @@ -296,13 +318,7 @@ startElement(void *userData, const char *name, const char **atts) } if (date) { - if (strlen(date) == strspn(date, "0123456789")) - repodata_set_num(pd->data, pd->datanum, SOLVABLE_BUILDTIME, atoi(date)); - else - { - /* FIXME: must convert to interger! */ - repodata_set_str(pd->data, pd->datanum, SOLVABLE_BUILDTIME, date); - } + repodata_set_num(pd->data, pd->datanum, SOLVABLE_BUILDTIME, datestr2timestamp(date)); } } break; @@ -351,13 +367,13 @@ startElement(void *userData, const char *name, const char **atts) /* Fedora 8 */ + /* Fedora 8 */ case STATE_NAME: break; /* - * + * * * -> patch.conflicts: {name} < {version}.{release} */ @@ -397,7 +413,7 @@ startElement(void *userData, const char *name, const char **atts) repodata_set_id(pd->data, pd->collhandle, UPDATE_COLLECTION_ARCH, a); break; } - /* libntlm-0.4.2-1.fc8.x86_64.rpm */ + /* libntlm-0.4.2-1.fc8.x86_64.rpm */ /* libntlm-0.4.2-1.fc8.x86_64.rpm */ case STATE_FILENAME: break; @@ -473,7 +489,7 @@ endElement(void *userData, const char *name) */ case STATE_DESCRIPTION: repodata_set_str(pd->data, pd->datanum, SOLVABLE_DESCRIPTION, pd->content); - break; + break; /* * Warning! ... */ @@ -490,7 +506,7 @@ endElement(void *userData, const char *name) repodata_add_flexarray(pd->data, pd->datanum, UPDATE_COLLECTION, pd->collhandle); pd->collhandle = 0; break; - /* libntlm-0.4.2-1.fc8.x86_64.rpm */ + /* libntlm-0.4.2-1.fc8.x86_64.rpm */ /* libntlm-0.4.2-1.fc8.x86_64.rpm */ case STATE_FILENAME: repodata_set_str(pd->data, pd->collhandle, UPDATE_COLLECTION_FILENAME, pd->content); -- 2.7.4