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 #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" 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]; diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 747484f4..cf572de4 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -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 diff --git a/src/pacman/package.c b/src/pacman/package.c index 01f4e973..459cb8d4 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -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"),