Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorAaron Griffin <aaronmgriffin@gmail.com>2007-09-19 00:21:56 -0500
committerAaron Griffin <aaronmgriffin@gmail.com>2007-09-28 00:25:57 -0500
commit47622eef4dd8fd86a0aa0e3ebdb7b33f7c9d6804 (patch)
tree4fb65c38ad6a8c8fb4577977d78b07b891be3a2f /lib/libalpm
parent219808714f94788a66a430786c552f60e95b1a01 (diff)
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')
-rw-r--r--lib/libalpm/add.c5
-rw-r--r--lib/libalpm/alpm.h4
-rw-r--r--lib/libalpm/be_files.c38
-rw-r--r--lib/libalpm/package.c16
-rw-r--r--lib/libalpm/package.h4
5 files changed, 44 insertions, 23 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 47a885ec..a5885064 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -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);
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index f208398d..be8286dd 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -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);
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"
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 96c264ac..26157edd 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -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")) {
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index 47d384b6..42ebe0e0 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -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];