terminated .lastupdate implementation for HTTP protocol

This commit is contained in:
Aurelien Foret 2006-01-05 19:37:54 +00:00
parent 9d55476c9c
commit 4819d21c74
4 changed files with 31 additions and 21 deletions

2
TODO
View file

@ -24,7 +24,7 @@ during packages replacement)
- review how things are displayed in the frontend (normal display, - review how things are displayed in the frontend (normal display,
verbose mode, which usage for the library log callback, debug levels, ...) verbose mode, which usage for the library log callback, debug levels, ...)
- add HTTP support for .lastupdate files - add .lastupdate files support for "files" db downloads
ADDITIONAL IDEAS FOR PERFORMANCE IMPROVEMENT ADDITIONAL IDEAS FOR PERFORMANCE IMPROVEMENT

View file

@ -279,13 +279,10 @@ int alpm_db_update(PM_DB *db, char *archive, char *ts)
} }
if(ts && strlen(ts) != 0) { if(ts && strlen(ts) != 0) {
char lastupdate[15]; if(strcmp(ts, db->lastupdate) == 0) {
if(db_getlastupdate(db, lastupdate) != -1) {
if(strcmp(ts, lastupdate) == 0) {
RET_ERR(PM_ERR_DB_UPTODATE, -1); RET_ERR(PM_ERR_DB_UPTODATE, -1);
} }
} }
}
/* remove the old dir */ /* remove the old dir */
_alpm_log(PM_LOG_FLOW2, "flushing database %s/%s", handle->dbpath, db->treename); _alpm_log(PM_LOG_FLOW2, "flushing database %s/%s", handle->dbpath, db->treename);

View file

@ -356,7 +356,7 @@ int downloadfiles_forreal(list_t *servers, const char *localpath,
fprintf(stderr, "warning: failed to get filesize for %s\n", fn); fprintf(stderr, "warning: failed to get filesize for %s\n", fn);
} }
/* check mtimes */ /* check mtimes */
if(mtime1 || mtime2) { if(mtime1 && strlen(mtime1)) {
char fmtime[64]; char fmtime[64];
if(!FtpModDate(fn, fmtime, sizeof(fmtime)-1, control)) { if(!FtpModDate(fn, fmtime, sizeof(fmtime)-1, control)) {
fprintf(stderr, "warning: failed to get mtime for %s\n", fn); fprintf(stderr, "warning: failed to get mtime for %s\n", fn);
@ -433,21 +433,30 @@ int downloadfiles_forreal(list_t *servers, const char *localpath,
} else { } else {
snprintf(src, PATH_MAX, "%s://%s%s%s", server->protocol, server->server, server->path, fn); snprintf(src, PATH_MAX, "%s://%s%s%s", server->protocol, server->server, server->path, fn);
} }
if(mtime1) { if(mtime1 && strlen(mtime1)) {
struct tm tmref;
time_t t, tref;
int diff;
/* date conversion from YYYYMMDDHHMMSS to "rfc1123-date" */ /* date conversion from YYYYMMDDHHMMSS to "rfc1123-date" */
sscanf(mtime1, "%4d%2d%2d%2d%2d%2d", sscanf(mtime1, "%4d%2d%2d%2d%2d%2d",
&fmtime1.tm_year, &fmtime1.tm_mon, &fmtime1.tm_mday, &fmtime1.tm_year, &fmtime1.tm_mon, &fmtime1.tm_mday,
&fmtime1.tm_hour, &fmtime1.tm_min, &fmtime1.tm_sec); &fmtime1.tm_hour, &fmtime1.tm_min, &fmtime1.tm_sec);
fmtime1.tm_year -= 1900; fmtime1.tm_year -= 1900;
fmtime1.tm_mon--; fmtime1.tm_mon--;
/* ORE - really compute the week day because some web servers (like lighttpd) /* compute the week day because some web servers (like lighttpd) need them. */
* need them. /* we set tmref to "Thu, 01 Jan 1970 00:00:00" */
* Fortunately, Apache does not use it: so our loosy implementation with a memset(&tmref, 0, sizeof(struct tm));
* hardcoded week day will work in almost all cases. */ tmref.tm_mday = 1;
fmtime1.tm_wday = 0; tref = mktime(&tmref);
/* then we compute the difference with mtime1 */
t = mktime(&fmtime1);
diff = ((t-tref)/3600/24)%7;
fmtime1.tm_wday = diff+(diff >= 3 ? -3 : 4);
} }
fmtime2.tm_year = 0; fmtime2.tm_year = 0;
if(!HttpGet(server->server, output, src, &fsz, control, offset, &fmtime1, &fmtime2)) { if(!HttpGet(server->server, output, src, &fsz, control, offset,
(mtime1) ? &fmtime1 : NULL, (mtime2) ? &fmtime2 : NULL)) {
if(strstr(FtpLastResponse(control), "304")) { if(strstr(FtpLastResponse(control), "304")) {
vprint("mtimes are identical, skipping %s\n", fn); vprint("mtimes are identical, skipping %s\n", fn);
filedone = -1; filedone = -1;
@ -457,13 +466,17 @@ int downloadfiles_forreal(list_t *servers, const char *localpath,
/* we leave the partially downloaded file in place so it can be resumed later */ /* we leave the partially downloaded file in place so it can be resumed later */
} }
} else { } else {
filedone = 1; if(mtime2) {
} if(fmtime2.tm_year) {
if(mtime2 && fmtime2.tm_year) {
/* date conversion from "rfc1123-date" to YYYYMMDDHHMMSS */ /* date conversion from "rfc1123-date" to YYYYMMDDHHMMSS */
sprintf(mtime2, "%4d%02d%02d%02d%02d%02d", sprintf(mtime2, "%4d%02d%02d%02d%02d%02d",
fmtime2.tm_year+1900, fmtime2.tm_mon+1, fmtime2.tm_mday, fmtime2.tm_year+1900, fmtime2.tm_mon+1, fmtime2.tm_mday,
fmtime2.tm_hour, fmtime2.tm_min, fmtime2.tm_sec); fmtime2.tm_hour, fmtime2.tm_min, fmtime2.tm_sec);
} else {
fprintf(stderr, "warning: failed to get mtime for %s\n", fn);
}
}
filedone = 1;
} }
} else if(!strcmp(server->protocol, "file")) { } else if(!strcmp(server->protocol, "file")) {
char src[PATH_MAX]; char src[PATH_MAX];

View file

@ -166,7 +166,7 @@ static int sync_synctree(list_t *syncs)
/* get the lastupdate time */ /* get the lastupdate time */
lastupdate = alpm_db_getinfo(sync->db, PM_DB_LASTUPDATE); lastupdate = alpm_db_getinfo(sync->db, PM_DB_LASTUPDATE);
if(lastupdate == NULL) { if(strlen(lastupdate) == 0) {
vprint("failed to get lastupdate time for %s (no big deal)\n", sync->treename); vprint("failed to get lastupdate time for %s (no big deal)\n", sync->treename);
} }