Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=27b629c2e14e444bac3c137c47375e67d98e8408

commit 27b629c2e14e444bac3c137c47375e67d98e8408
Author: Michel Hermier <herm...@frugalware.org>
Date:   Thu Nov 14 08:23:12 2013 +0100

libpacman: Make mtime1 a time_t in _pacman_downloadfiles_forreal.

diff --git a/lib/libpacman/db/syncdb.c b/lib/libpacman/db/syncdb.c
index 85a16c8..2e7d73e 100644
--- a/lib/libpacman/db/syncdb.c
+++ b/lib/libpacman/db/syncdb.c
@@ -94,14 +94,14 @@ int _pacman_syncdb_update(pmdb_t *db, int force)
{
char path[PATH_MAX], dirpath[PATH_MAX];
pmlist_t *files = NULL;
-       time_t newmtime = (time_t) -1;
-       char lastupdate[16] = "";
+       time_t newmtime = ((time_t) -1);
+       time_t timestamp = ((time_t) -1);
int ret, updated=0;

if(!force) {
/* get the lastupdate time */
-               _pacman_db_getlastupdate(db, lastupdate);
-               if(_pacman_strempty(lastupdate)) {
+               _pacman_db_gettimestamp(db, &timestamp);
+               if(timestamp == ((time_t) -1)) {
_pacman_log(PM_LOG_DEBUG, _("failed to get lastupdate time for %s (no big 
deal)\n"), db->treename);
}
}
@@ -112,7 +112,7 @@ int _pacman_syncdb_update(pmdb_t *db, int force)

snprintf(path, PATH_MAX, "%s%s", handle->root, handle->dbpath);

-       ret = _pacman_downloadfiles_forreal(db->servers, path, files, 
lastupdate, &newmtime, 0);
+       ret = _pacman_downloadfiles_forreal(db->servers, path, files, 
&timestamp, &newmtime, 0);
FREELIST(files);
if(ret != 0) {
if(ret == -1) {
diff --git a/lib/libpacman/server.c b/lib/libpacman/server.c
index d454f98..52d1f03 100644
--- a/lib/libpacman/server.c
+++ b/lib/libpacman/server.c
@@ -155,7 +155,7 @@ int _pacman_downloadfiles(pmlist_t *servers, const char 
*localpath, pmlist_t *fi
*         -1 on error
*/
int _pacman_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
-       pmlist_t *files, const char *mtime1, time_t *mtime2, int skip)
+       pmlist_t *files, const time_t *mtime1, time_t *mtime2, int skip)
{
int fsz;
netbuf *control = NULL;
@@ -391,19 +391,21 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, 
const char *localpath,
if(!FtpModDate(fn, fmtime, sizeof(fmtime)-1, control)) {
_pacman_log(PM_LOG_WARNING, _("failed to get mtime for %s\n"), fn);
} else {
+                                                       time_t mdtm;
+
_pacman_strtrim(fmtime);
-                                                       if(mtime1 && 
!strcmp(mtime1, fmtime)) {
-                                                               /* mtimes are 
identical, skip this file */
-                                                               
_pacman_log(PM_LOG_DEBUG, _("mtimes are identical, skipping %s\n"), fn);
-                                                               filedone = -1;
-                                                               complete = 
_pacman_list_add(complete, fn);
-                                                       } else {
-                                                               if(mtime2) {
-                                                                       
if(_pacman_ftp_strpmdtm(fmtime, mtime2) == NULL) {
-                                                                               
_pacman_log(PM_LOG_WARNING, _("failed to get mtime for %s\n"), fn);
-                                                                               
*mtime2 = (time_t) -1;
+                                                       
if(_pacman_ftp_strpmdtm(fmtime, &mdtm) != NULL) {
+                                                               if(mtime1 && 
difftime(mdtm, mtime1) == 0) {
+                                                                       
_pacman_log(PM_LOG_DEBUG, _("mtimes are identical, skipping %s\n"), fn);
+                                                                       
filedone = -1;
+                                                                       
complete = _pacman_list_add(complete, fn);
+                                                               } else {
+                                                                       
if(mtime2) {
+                                                                               
*mtime2 = mdtm;
}
}
+                                                       } else {
+                                                               
_pacman_log(PM_LOG_WARNING, _("failed to get mtime for %s\n"), fn);
}
}
}
@@ -482,27 +484,8 @@ int _pacman_downloadfiles_forreal(pmlist_t *servers, const 
char *localpath,
} else {
snprintf(src, PATH_MAX, "%s://%s%s%s", server->protocol, server->server, 
server->path, fn);
}
-                                       if(mtime1 && strlen(mtime1)) {
-                                               struct tm tmref;
-                                               time_t t, tref;
-                                               int diff;
-                                               /* date conversion from 
YYYYMMDDHHMMSS to "rfc1123-date" */
-                                               sscanf(mtime1, 
"%4d%2d%2d%2d%2d%2d",
-                                                      &fmtime1.tm_year, 
&fmtime1.tm_mon, &fmtime1.tm_mday,
-                                                      &fmtime1.tm_hour, 
&fmtime1.tm_min, &fmtime1.tm_sec);
-                                               fmtime1.tm_year -= 1900;
-                                               fmtime1.tm_mon--;
-                                               /* compute the week day because 
some web servers (like lighttpd) need them. */
-                                               /* we set tmref to "Thu, 01 Jan 
1970 00:00:00" */
-                                               memset(&tmref, 0, sizeof(struct 
tm));
-                                               tmref.tm_mday = 1;
-                                               tref = mktime(&tmref);
-                                               /* then we compute the 
difference with mtime1 */
-                                               memcpy(&tmref, &fmtime1, 
sizeof(struct tm));
-                                               t = mktime(&tmref);
-                                               diff = ((t-tref)/3600/24)%7;
-                                               fmtime1.tm_wday = diff+(diff >= 
3 ? -3 : 4);
-
+                                       if(mtime1 && *mtime1 != ((time_t) -1)) {
+                                               fmtime1 = *gmtime(mtime1);
}
if(!HttpGet(server->server, output, src, &fsz, control, (pm_dloffset ? 
*pm_dloffset:0),
(mtime1) ? &fmtime1 : NULL, (mtime2) ? &fmtime2 : NULL)) {
diff --git a/lib/libpacman/server.h b/lib/libpacman/server.h
index 4a96508..a3bf369 100644
--- a/lib/libpacman/server.h
+++ b/lib/libpacman/server.h
@@ -47,7 +47,7 @@ pmserver_t *_pacman_server_new(char *url);
void _pacman_server_free(void *data);
int _pacman_downloadfiles(pmlist_t *servers, const char *localpath, pmlist_t 
*files, int skip);
int _pacman_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
-       pmlist_t *files, const char *mtime1, time_t *mtime2, int skip);
+       pmlist_t *files, const time_t *mtime1, time_t *mtime2, int skip);

char *_pacman_fetch_pkgurl(char *target);
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to