Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=5f7e4a4cf43b0c1bc5a92246a1bb1f32281fdcd4
commit 5f7e4a4cf43b0c1bc5a92246a1bb1f32281fdcd4 Author: Michel Hermier <[email protected]> Date: Fri Aug 1 09:29:57 2014 +0200 libpacman: Wramp timestamp values in a libpacman::Timestamp class. diff --git a/lib/libpacman/CMakeLists.txt b/lib/libpacman/CMakeLists.txt index 7afad86..76caf4d 100644 --- a/lib/libpacman/CMakeLists.txt +++ b/lib/libpacman/CMakeLists.txt @@ -64,6 +64,7 @@ set(LIBPACMAN_SOURCES pacman.cpp server.cpp sync.cpp + timestamp.h trans.cpp trans_sysupgrade.cpp util.cpp diff --git a/lib/libpacman/db.cpp b/lib/libpacman/db.cpp index ad1b8c5..6b02cd2 100644 --- a/lib/libpacman/db.cpp +++ b/lib/libpacman/db.cpp @@ -133,7 +133,7 @@ int Database::open(int flags) return open(flags, &cache_timestamp); } -int Database::open(int flags, time_t *timestamp) +int Database::open(int flags, Timestamp *timestamp) { return -1; } @@ -143,14 +143,14 @@ int Database::close() return -1; } -int Database::gettimestamp(time_t *timestamp) +int Database::gettimestamp(Timestamp *timestamp) { ASSERT(timestamp != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); char buffer[PM_FMT_MDTM_MAX]; if(_pacman_db_getlastupdate(this, buffer) == 0 && - _pacman_ftp_strpmdtm(buffer, timestamp) != NULL) { + _pacman_ftp_strpmdtm(buffer, timestamp != NULL ? ×tamp->m_value : NULL) != NULL) { return 0; } return -1; @@ -158,11 +158,11 @@ int Database::gettimestamp(time_t *timestamp) /* A NULL timestamp means now per f_localtime definition. */ -int Database::settimestamp(const time_t *timestamp) +int Database::settimestamp(const Timestamp *timestamp) { char buffer[PM_FMT_MDTM_MAX]; - _pacman_ftp_strfmdtm(buffer, sizeof(buffer), timestamp); + _pacman_ftp_strfmdtm(buffer, sizeof(buffer), timestamp != NULL ? ×tamp->m_value : NULL); return _pacman_db_setlastupdate(this, buffer); } diff --git a/lib/libpacman/db.h b/lib/libpacman/db.h index a4292ea..516b7d6 100644 --- a/lib/libpacman/db.h +++ b/lib/libpacman/db.h @@ -27,6 +27,7 @@ #include <time.h> #include "handle.h" +#include "timestamp.h" #include "kernel/fobject.h" @@ -52,8 +53,8 @@ public: virtual int open(int flags = 0); virtual int close(); - virtual int gettimestamp(time_t *timestamp); - virtual int settimestamp(const time_t *timestamp); + virtual int gettimestamp(libpacman::Timestamp *timestamp); + virtual int settimestamp(const libpacman::Timestamp *timestamp); /* Package iterator */ virtual int rewind(); @@ -70,7 +71,7 @@ public: ::libpacman::Handle *m_handle; char *path; char treename[PATH_MAX]; - time_t cache_timestamp; + libpacman::Timestamp cache_timestamp; pmlist_t *pkgcache; pmlist_t *grpcache; pmlist_t *servers; @@ -78,7 +79,7 @@ public: protected: Database(libpacman::Handle *handle, const char *treename); - virtual int open(int flags, time_t *timestamp); + virtual int open(int flags, libpacman::Timestamp *timestamp); private: }; diff --git a/lib/libpacman/db/localdb.cpp b/lib/libpacman/db/localdb.cpp index d39495c..db09d6e 100644 --- a/lib/libpacman/db/localdb.cpp +++ b/lib/libpacman/db/localdb.cpp @@ -287,7 +287,7 @@ pmlist_t *LocalDatabase::test() const return(ret); } -int LocalDatabase::open(int flags, time_t *timestamp) +int LocalDatabase::open(int flags, Timestamp *timestamp) { struct stat buf; diff --git a/lib/libpacman/db/localdb.h b/lib/libpacman/db/localdb.h index 28bcfb8..6536125 100644 --- a/lib/libpacman/db/localdb.h +++ b/lib/libpacman/db/localdb.h @@ -64,7 +64,7 @@ public: virtual pmlist_t *getowners(const char *filename); protected: - virtual int open(int flags, time_t *timestamp); + virtual int open(int flags, libpacman::Timestamp *timestamp); private: DIR *m_dir; diff --git a/lib/libpacman/db/syncdb.cpp b/lib/libpacman/db/syncdb.cpp index 5f10b97..7ba557f 100644 --- a/lib/libpacman/db/syncdb.cpp +++ b/lib/libpacman/db/syncdb.cpp @@ -153,14 +153,14 @@ int _pacman_syncdb_update(Database *db, int force) { char path[PATH_MAX], dirpath[PATH_MAX]; pmlist_t *files = NULL; - time_t newmtime = PM_TIME_INVALID; - time_t timestamp = PM_TIME_INVALID; + Timestamp newmtime; + Timestamp timestamp; int ret, updated=0; Handle *handle = db->m_handle; if(!force) { db->gettimestamp(×tamp); - if(timestamp == PM_TIME_INVALID) { + if(!timestamp.isValid()) { _pacman_log(PM_LOG_DEBUG, _("failed to get timestamp for %s (no big deal)\n"), db->treename); } } @@ -180,7 +180,7 @@ int _pacman_syncdb_update(Database *db, int force) } return 1; /* Means up2date */ } else { - if(newmtime != PM_TIME_INVALID) { + if(newmtime.isValid()) { _pacman_log(PM_LOG_DEBUG, _("sync: new mtime for %s: %s\n"), db->treename, newmtime); updated = 1; } @@ -200,7 +200,7 @@ int _pacman_syncdb_update(Database *db, int force) return 0; } -int SyncDatabase::open(int flags, time_t *timestamp) +int SyncDatabase::open(int flags, Timestamp *timestamp) { struct stat buf; char dbpath[PATH_MAX]; diff --git a/lib/libpacman/db/syncdb.h b/lib/libpacman/db/syncdb.h index 2b17573..70803ff 100644 --- a/lib/libpacman/db/syncdb.h +++ b/lib/libpacman/db/syncdb.h @@ -59,7 +59,7 @@ public: virtual libpacman::Package *scan(const char *target, unsigned int inforeq); protected: - virtual int open(int flags, time_t *timestamp); + virtual int open(int flags, libpacman::Timestamp *timestamp); public: // FIXME: Make private struct archive *m_archive; diff --git a/lib/libpacman/io/ftp.c b/lib/libpacman/io/ftp.c index b263f48..2845fc7 100644 --- a/lib/libpacman/io/ftp.c +++ b/lib/libpacman/io/ftp.c @@ -32,7 +32,7 @@ size_t _pacman_ftp_strfmdtm(char *s, size_t max, const time_t *time) { - return strftime(s, max, PM_FTP_MDTM_FORMAT, f_localtime(time)); + return strftime(s, max, PM_FTP_MDTM_FORMAT, time != NULL ? gmtime(time) : f_localtime(NULL)); } char *_pacman_ftp_strpmdtm(const char *s, time_t *time) diff --git a/lib/libpacman/server.cpp b/lib/libpacman/server.cpp index f0557e2..371927b 100644 --- a/lib/libpacman/server.cpp +++ b/lib/libpacman/server.cpp @@ -242,7 +242,7 @@ int _pacman_curl_fini(pmcurldownloader_t *curldownloader) static pmdownloadsuccess_t _pacman_curl_download(pmcurldownloader_t *curldownloader, const char *url, - const time_t *mtime1, time_t *mtime2, const char *output, pmfiletype_t dlFileType) + const Timestamp *mtime1, Timestamp *mtime2, const char *output, pmfiletype_t dlFileType) { CURL *curlHandle = curldownloader->curl; FILE *outputFile; @@ -257,7 +257,7 @@ pmdownloadsuccess_t _pacman_curl_download(pmcurldownloader_t *curldownloader, co if(mtime1 && mtime2 && !curldownloader->m_handle->proxyhost) { curl_easy_setopt(curlHandle, CURLOPT_FILETIME, 1); curl_easy_setopt(curlHandle, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE); - curl_easy_setopt(curlHandle, CURLOPT_TIMEVALUE , (long)*mtime1); + curl_easy_setopt(curlHandle, CURLOPT_TIMEVALUE , (long)mtime1->m_value); outputFile = fopen(output,"wb"); } else { struct stat st; @@ -362,7 +362,7 @@ int _pacman_downloadfiles(Handle *handle, pmlist_t *servers, const char *localpa * -1 on error */ int _pacman_downloadfiles_forreal(Handle *handle, pmlist_t *servers, const char *localpath, - pmlist_t *files, const time_t *mtime1, time_t *mtime2, int skip) + pmlist_t *files, const Timestamp *mtime1, Timestamp *mtime2, int skip) { pmlist_t *lp; int done = 0; diff --git a/lib/libpacman/server.h b/lib/libpacman/server.h index 6aa1091..aa3a6bc 100644 --- a/lib/libpacman/server.h +++ b/lib/libpacman/server.h @@ -21,11 +21,10 @@ #ifndef _PACMAN_SERVER_H #define _PACMAN_SERVER_H -#include <time.h> - #include "pacman.h" #include "handle.h" +#include "timestamp.h" #define FREELISTSERVERS(p) _FREELIST(p, _pacman_server_free) @@ -52,7 +51,7 @@ pmserver_t *_pacman_server_new(char *url); void _pacman_server_free(void *data); int _pacman_downloadfiles(::libpacman::Handle *handle, pmlist_t *servers, const char *localpath, pmlist_t *files, int skip); int _pacman_downloadfiles_forreal(::libpacman::Handle *handle, pmlist_t *servers, const char *localpath, - pmlist_t *files, const time_t *mtime1, time_t *mtime2, int skip); + pmlist_t *files, const libpacman::Timestamp *mtime1, libpacman::Timestamp *mtime2, int skip); char *_pacman_fetch_pkgurl(::libpacman::Handle *handle, char *target); diff --git a/lib/libpacman/timestamp.h b/lib/libpacman/timestamp.h new file mode 100644 index 0000000..c4b246a --- /dev/null +++ b/lib/libpacman/timestamp.h @@ -0,0 +1,60 @@ +/* + * timestamp.h + * + * Copyright (c) 2014 by Michel Hermier <[email protected]> + * + * 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_TIMESTAMP_H +#define _PACMAN_TIMESTAMP_H + +#include "util/time.h" + +namespace libpacman { + +struct Timestamp +{ + Timestamp() + : m_value(PM_TIME_INVALID) + { } + + Timestamp(const time_t &epoch) + : m_value(epoch) + { } + + double operator - (const libpacman::Timestamp &other) const + { + return difftime(m_value, &other.m_value); + } + + bool operator == (const time_t &epoch) const + { + return m_value == epoch; + } + + bool isValid() const + { + return m_value != PM_TIME_INVALID; + } + + time_t m_value; +}; + +} + +#endif /* _PACMAN_TIMESTAMP_H */ + +/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/trans.cpp b/lib/libpacman/trans.cpp index 18438f4..97e8e94 100644 --- a/lib/libpacman/trans.cpp +++ b/lib/libpacman/trans.cpp @@ -63,12 +63,12 @@ using namespace libpacman; static int check_oldcache(Database *db) { - time_t timestamp; + Timestamp timestamp; if(db->gettimestamp(×tamp) == -1) { return(-1); } - if(difftime(timestamp, db->cache_timestamp) != 0) { + if(timestamp - db->cache_timestamp != 0) { _pacman_log(PM_LOG_DEBUG, _("cache for '%s' repo is too old"), db->treename); _pacman_db_free_pkgcache(db); } else { @@ -246,7 +246,7 @@ static int pkg_cmp(const void *p1, const void *p2) static int check_olddelay(void) { pmlist_t *i; - time_t tm; + Timestamp tm; if(!handle->olddelay) { return(0); @@ -257,7 +257,7 @@ static int check_olddelay(void) if(db->gettimestamp(&tm) == -1) { continue; } - if(difftime(time(NULL), tm) > handle->olddelay) { + if(difftime(time(NULL), tm.m_value) > handle->olddelay) { _pacman_log(PM_LOG_WARNING, _("local copy of '%s' repo is too old"), db->treename); } } _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
