From a9fb4d9d5b065560f7e42378ad1ee3d2f7b19911 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Fri, 25 Mar 2011 09:15:30 -0400 Subject: 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 Signed-off-by: Dan McGee --- lib/libalpm/dload.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'lib/libalpm') 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); -- cgit v1.2.3-70-g09d2