summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-03-25 14:15:30 +0100
committerDan McGee <dan@archlinux.org>2011-03-28 03:14:47 +0200
commita9fb4d9d5b065560f7e42378ad1ee3d2f7b19911 (patch)
tree4a2d12aded86f85199b970d6f4ce848fe7093cc5
parent98c8ab18ff7f48bb2074d821ad93b009fd4bac4c (diff)
downloadpacman-a9fb4d9d5b065560f7e42378ad1ee3d2f7b19911.tar.gz
pacman-a9fb4d9d5b065560f7e42378ad1ee3d2f7b19911.tar.xz
lib/dload: abstract out helper function to set utimes
This greatly simplifies the cleanup fallthrough in our download function and we'll be able to reuse this for signatures. Signed-off-by: Dave Reisner <d@falconindy.com> Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--lib/libalpm/dload.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index bc2a761b..d9e9488a 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -142,6 +142,18 @@ static int curl_gethost(const char *url, char *buffer)
return 0;
}
+static int utimes_long(const char *path, long time)
+{
+ if(time != -1) {
+ struct timeval tv[2];
+ memset(&tv, 0, sizeof(tv));
+ tv[0].tv_sec = tv[1].tv_sec = time;
+ return utimes(path, tv);
+ }
+ return 0;
+}
+
+
static int curl_download_internal(const char *url, const char *localpath,
int force)
{
@@ -265,35 +277,23 @@ static int curl_download_internal(const char *url, const char *localpath,
goto cleanup;
}
- fclose(localf);
- localf = NULL;
-
- /* set the times on the file to the same as that of the remote file */
- if(remote_time != -1) {
- struct timeval tv[2];
- memset(&tv, 0, sizeof(tv));
- tv[0].tv_sec = tv[1].tv_sec = remote_time;
- utimes(tempfile, tv);
- }
- rename(tempfile, destfile);
ret = 0;
cleanup:
- FREE(tempfile);
- FREE(destfile);
if(localf != NULL) {
- /* if we still had a local file open, we got interrupted. set the mtimes on
- * the file accordingly. */
- fflush(localf);
- if(remote_time != -1) {
- struct timeval tv[2];
- memset(&tv, 0, sizeof(tv));
- tv[0].tv_sec = tv[1].tv_sec = remote_time;
- futimes(fileno(localf), tv);
- }
fclose(localf);
+ utimes_long(tempfile, remote_time);
}
+ /* TODO: A signature download will need to return success here as well before
+ * we're willing to rotate the new file into place. */
+ if(ret == 0) {
+ rename(tempfile, destfile);
+ }
+
+ FREE(tempfile);
+ FREE(destfile);
+
/* restore the old signal handlers */
sigaction(SIGINT, &sig_int[OLD], NULL);
sigaction(SIGPIPE, &sig_pipe[OLD], NULL);