diff options
author | Dan McGee <dan@archlinux.org> | 2009-11-11 23:39:26 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2009-11-15 19:47:30 -0600 |
commit | d2dbb04a9af7a18da217fb21b9152626c43461da (patch) | |
tree | d0d3f7f1d19ce5e14031ecfcd32924036215224a /lib/libalpm/be_files.c | |
parent | be266b43647ef57632d7bcfd07a4441f737b5aed (diff) | |
download | pacman-d2dbb04a9af7a18da217fb21b9152626c43461da.tar.xz |
download: major refactor to address lingering issues
Sorry for this being such a huge patch, but I believe it is necessary for
quite a few reasons which I will attempt to explain herein. I've been
mulling this over for a while, but wasn't super happy with making the
download interface more complex. Instead, if we carefully order things in
the internal download code, we can actually make the interface simpler.
1. FS#15657 - This involves `name.db.tar.gz.part` files being left around the
filesystem, and then causing all sorts of issues when someone attempts to
rerun the operation they canceled. We need to ensure that if we resume a
download, we are resuming it on exactly the same file; if we cannot be
almost postive of that then we need to start over.
2. http://www.mail-archive.com/pacman-dev@archlinux.org/msg03536.html - Here
we have a lighttpd bug to ruin the day. If we send both a Range: header and
If-Modified-Since: header across the wire in a GET request, lighttpd doesn't
do what we want in several cases. If the file hadn't been modified, it
returns a '304 Not Modified' instead of a '206 Partial Content'. We need to
do a stat (e.g. HEAD in HTTP terms) operation here, and the proceed
accordingly based off the values we get back from it.
3. The mtime stuff was rather ugly, and relied on the called function to
write back to a passed in reference, which isn't the greatest. Instead, use
the power of the filesystem to contain this info. Every file downloaded
internally is now carefully timestamped with the remote file time. This
should allow the resume logic to work. In order to guarantee this, we need
to implement a signal handler that catches interrupts, notifies the running
code, and causes it to set the mtimes on the file. It then rethrows the
signal so the pacman signal handler (or any frontend) works as expected.
4. We did a lot of funky stuff in trying to track the DB last modified time.
It is a lot easier to just keep the downloaded DB file around and track the
time on that rather than in a funky dot file. It also kills a lot of code.
5. For GPG verification of the databases down the road, we are going to need
the DB file around for at least a short bit of time anyway, so this gets us
closer to that.
Signed-off-by: Dan McGee <dan@archlinux.org>
[Xav: fixed printf with off_t]
Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
Diffstat (limited to 'lib/libalpm/be_files.c')
-rw-r--r-- | lib/libalpm/be_files.c | 96 |
1 files changed, 5 insertions, 91 deletions
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index ffbaa8d5..90e97a55 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -47,76 +47,6 @@ #include "dload.h" -/* - * Return the last update time as number of seconds from the epoch. - * Returns 0 if the value is unknown or can't be read. - */ -static time_t getlastupdate(pmdb_t *db) -{ - FILE *fp; - char *file; - const char *dbpath; - time_t ret = 0; - - ALPM_LOG_FUNC; - - if(db == NULL) { - return(ret); - } - - dbpath = _alpm_db_path(db); - /* dbpath + '.lastupdate' + NULL */ - MALLOC(file, strlen(dbpath) + 12, RET_ERR(PM_ERR_MEMORY, ret)); - sprintf(file, "%s.lastupdate", dbpath); - - /* get the last update time, if it's there */ - if((fp = fopen(file, "r")) == NULL) { - free(file); - return(ret); - } else { - char line[64]; - if(fgets(line, sizeof(line), fp)) { - ret = atol(line); - } - } - fclose(fp); - free(file); - return(ret); -} - -/* - * writes the dbpath/.lastupdate file with the value in time - */ -static int setlastupdate(pmdb_t *db, time_t time) -{ - FILE *fp; - char *file; - const char *dbpath; - int ret = 0; - - ALPM_LOG_FUNC; - - if(db == NULL || time == 0) { - return(-1); - } - - dbpath = _alpm_db_path(db); - /* dbpath + '.lastupdate' + NULL */ - MALLOC(file, strlen(dbpath) + 12, RET_ERR(PM_ERR_MEMORY, ret)); - sprintf(file, "%s.lastupdate", dbpath); - - if((fp = fopen(file, "w")) == NULL) { - free(file); - return(-1); - } - if(fprintf(fp, "%ju", (uintmax_t)time) <= 0) { - ret = -1; - } - fclose(fp); - free(file); - return(ret); -} - static int checkdbdir(pmdb_t *db) { struct stat buf; @@ -178,7 +108,6 @@ static int checkdbdir(pmdb_t *db) int SYMEXPORT alpm_db_update(int force, pmdb_t *db) { char *dbfile, *dbfilepath; - time_t newmtime = 0, lastupdate = 0; const char *dbpath; size_t len; @@ -200,27 +129,17 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) RET_ERR(PM_ERR_DB_NOT_FOUND, -1); } - if(!force) { - /* get the lastupdate time */ - lastupdate = getlastupdate(db); - if(lastupdate == 0) { - _alpm_log(PM_LOG_DEBUG, "failed to get lastupdate time for %s\n", - db->treename); - } - } - len = strlen(db->treename) + strlen(DBEXT) + 1; MALLOC(dbfile, len, RET_ERR(PM_ERR_MEMORY, -1)); sprintf(dbfile, "%s" DBEXT, db->treename); dbpath = alpm_option_get_dbpath(); - ret = _alpm_download_single_file(dbfile, db->servers, dbpath, - lastupdate, &newmtime); + ret = _alpm_download_single_file(dbfile, db->servers, dbpath, force); free(dbfile); if(ret == 1) { - /* mtimes match, do nothing */ + /* files match, do nothing */ pm_errno = 0; return(1); } else if(ret == -1) { @@ -233,8 +152,11 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) if(_alpm_rmrf(syncdbpath) != 0) { _alpm_log(PM_LOG_ERROR, _("could not remove database %s\n"), db->treename); RET_ERR(PM_ERR_DB_REMOVE, -1); + } else { + _alpm_log(PM_LOG_DEBUG, "database dir %s removed\n", _alpm_db_path(db)); } + /* Cache needs to be rebuilt */ _alpm_db_free_pkgcache(db); @@ -250,15 +172,7 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) free(dbfilepath); RET_ERR(PM_ERR_SYSTEM, -1); } - unlink(dbfilepath); free(dbfilepath); - - /* if we have a new mtime, set the DB last update value */ - if(newmtime) { - _alpm_log(PM_LOG_DEBUG, "sync: new mtime for %s: %ju\n", - db->treename, (uintmax_t)newmtime); - setlastupdate(db, newmtime); - } } return(0); |