1
0
mirror of https://github.com/moparisthebest/pacman synced 2025-01-08 12:28:00 -05:00

Fix some issues with localized dates/epoch usage

Commit 47622eef4d introduced localized times
in the metadata by way of storing the UNIX epoch value instead of a hard
coded date string. However, it missed a few things:
* If we weren't in the C/POSIX/en_US locale, the date parsing would fail
  as it tried to use the abbreviations of the locale being used. Fix this
  by switching the LC_TIME value before we parse a date.
* We used ctime to print the date value, which is always the C locale
  string. Instead, use strftime to print a localized date string.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2007-11-08 23:18:07 -06:00
parent 5b4b4df4c9
commit e6673544b2
3 changed files with 11 additions and 2 deletions

View File

@ -337,8 +337,10 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
char first = tolower(tmp[0]);
if(first > 'a' && first < 'z') {
struct tm tmp_tm = {0}; //initialize to null incase of failure
setlocale(LC_TIME, "C");
strptime(tmp, "%a %b %e %H:%M:%S %Y", &tmp_tm);
info->builddate = mktime(&tmp_tm);
setlocale(LC_TIME, "");
} else {
info->builddate = atol(tmp);
}
@ -352,8 +354,10 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
char first = tolower(tmp[0]);
if(first > 'a' && first < 'z') {
struct tm tmp_tm = {0}; //initialize to null incase of failure
setlocale(LC_TIME, "C");
strptime(tmp, "%a %b %e %H:%M:%S %Y", &tmp_tm);
info->installdate = mktime(&tmp_tm);
setlocale(LC_TIME, "");
} else {
info->installdate = atol(tmp);
}

View File

@ -852,8 +852,10 @@ static int parse_descfile(const char *descfile, pmpkg_t *info)
char first = tolower(ptr[0]);
if(first > 'a' && first < 'z') {
struct tm tmp_tm = {0}; //initialize to null incase of failure
setlocale(LC_TIME, "C");
strptime(ptr, "%a %b %e %H:%M:%S %Y", &tmp_tm);
info->builddate = mktime(&tmp_tm);
setlocale(LC_TIME, "");
} else {
info->builddate = atol(ptr);
}

View File

@ -45,6 +45,7 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
{
const char *reason, *descheader;
time_t bdate, idate;
char bdatestr[50], idatestr[50];
if(pkg == NULL) {
return;
@ -52,7 +53,9 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
/* set variables here, do all output below */
bdate = alpm_pkg_get_builddate(pkg);
strftime(bdatestr, 50, "%c", localtime(&bdate));
idate = alpm_pkg_get_installdate(pkg);
strftime(idatestr, 50, "%c", localtime(&idate));
switch((long)alpm_pkg_get_reason(pkg)) {
case PM_PKG_REASON_EXPLICIT:
@ -86,9 +89,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"), ctime(&bdate)); /*ctime implicit newline */
printf(_("Build Date : %s\n"), bdatestr);
if(level > 0) {
printf(_("Install Date : %s"), ctime(&idate)); /*ctime implicit newline */
printf(_("Install Date : %s\n"), idatestr);
printf(_("Install Reason : %s\n"), reason);
}
printf(_("Install Script : %s\n"),