Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=83759db780a04fd902da1996063d1e9418979770
commit 83759db780a04fd902da1996063d1e9418979770 Author: Michel Hermier <herm...@frugalware.org> Date: Wed Nov 13 21:35:04 2013 +0100 libpacman: Add ftp helper to parse mdtm formated strings. diff --git a/lib/libpacman/Makefile.am b/lib/libpacman/Makefile.am index b9e19d1..6e631bd 100644 --- a/lib/libpacman/Makefile.am +++ b/lib/libpacman/Makefile.am @@ -19,7 +19,8 @@ HASH_TARGETS = \ hash/sha1.c IO_TARGETS = \ - io/archive.c + io/archive.c \ + io/ftp.c PACKAGE_TARGETS = \ package/pkginfo.c diff --git a/lib/libpacman/db.c b/lib/libpacman/db.c index a313cbf..cee5097 100644 --- a/lib/libpacman/db.c +++ b/lib/libpacman/db.c @@ -46,6 +46,7 @@ #include "db/localdb.h" #include "db/syncdb.h" +#include "io/ftp.h" #include "util/list.h" #include "util/log.h" #include "util/time.h" @@ -195,13 +196,9 @@ int _pacman_db_gettimestamp(pmdb_t *db, time_t *timestamp) } else { char buffer[16]; - if(_pacman_db_getlastupdate(db, buffer) == 0) { - struct tm ptimestamp = { 0 }; - - if(strptime(buffer, "%Y%m%d%H%M%S", &ptimestamp) != NULL) { - *timestamp = mktime(&ptimestamp); - return 0; - } + if(_pacman_db_getlastupdate(db, buffer) == 0 && + _pacman_ftp_strpmdtm(buffer, timestamp) != NULL) { + return 0; } return -1; } @@ -215,7 +212,7 @@ int _pacman_db_settimestamp(pmdb_t *db, const time_t *timestamp) ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); - strftime(buffer, sizeof(buffer), "%Y%m%d%H%M%S", _pacman_localtime(timestamp)); + _pacman_ftp_strfmdtm(buffer, sizeof(buffer), timestamp); return _pacman_db_setlastupdate(db, buffer); } diff --git a/lib/libpacman/io/ftp.c b/lib/libpacman/io/ftp.c new file mode 100644 index 0000000..373084f --- /dev/null +++ b/lib/libpacman/io/ftp.c @@ -0,0 +1,57 @@ +/* + * ftp.c + * + * Copyright (c) 2013 by Michel Hermier <herm...@frugalware.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + +#include "config.h" + +#include <stdio.h> + +#include "io/ftp.h" + +#include "util/time.h" +#include "util.h" + +#define PM_FTP_MDTM_FORMAT "%Y%m%d%H%M%S" + +size_t _pacman_ftp_strfmdtm(char *s, size_t max, const time_t *time) +{ + return strftime(s, max, PM_FTP_MDTM_FORMAT, _pacman_localtime(time)); +} + +char *_pacman_ftp_strpmdtm(const char *s, time_t *time) +{ + char *ret; + struct tm ptimestamp = { 0 }; + + ASSERT(time != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL)); + + if((ret = strptime(s, PM_FTP_MDTM_FORMAT, &ptimestamp)) != NULL) { + time_t tmp; + + if((tmp = mktime(&ptimestamp)) != ((time_t) -1)) { + *time = tmp; + } else { + ret = NULL; + } + } + return ret; +} + +/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/io/ftp.h b/lib/libpacman/io/ftp.h new file mode 100644 index 0000000..e2f08c7 --- /dev/null +++ b/lib/libpacman/io/ftp.h @@ -0,0 +1,31 @@ +/* + * ftp.h + * + * Copyright (c) 2013 by Michel Hermier <herm...@frugalware.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ +#ifndef _PACMAN_FTP_H +#define _PACMAN_FTP_H + +#include <time.h> + +size_t _pacman_ftp_strfmdtm(char *s, size_t max, const time_t *time); +char *_pacman_ftp_strpmdtm(const char *s, time_t *time); + +#endif /* _PACMAN_FTP_H */ + +/* vim: set ts=2 sw=2 noet: */ _______________________________________________ Frugalware-git mailing list Frugalware-git@frugalware.org http://frugalware.org/mailman/listinfo/frugalware-git