From 59165c5c30f6f9be34721176c7515b9056b1ddab Mon Sep 17 00:00:00 2001 From: des Date: Wed, 19 Oct 2011 12:14:14 +0000 Subject: [PATCH] MFH r225599,225800,225805: improve handling of resumed http transfers PR: bin/117277 git-svn-id: svn://svn.freebsd.org/base/stable/8@226540 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.bin/fetch/fetch.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c index 7553bd8d1..11b714fe4 100644 --- a/usr.bin/fetch/fetch.c +++ b/usr.bin/fetch/fetch.c @@ -522,6 +522,12 @@ fetch(char *URL, const char *path) "does not match remote", path); goto failure_keep; } + } else if (url->offset > sb.st_size) { + /* gap between what we asked for and what we got */ + warnx("%s: gap in resume mode", URL); + fclose(of); + of = NULL; + /* picked up again later */ } else if (us.size != -1) { if (us.size == sb.st_size) /* nothing to do */ @@ -534,7 +540,7 @@ fetch(char *URL, const char *path) goto failure; } /* we got it, open local file */ - if ((of = fopen(path, "a")) == NULL) { + if ((of = fopen(path, "r+")) == NULL) { warn("%s: fopen()", path); goto failure; } @@ -551,8 +557,16 @@ fetch(char *URL, const char *path) fclose(of); of = NULL; sb = nsb; + /* picked up again later */ } } + /* seek to where we left off */ + if (of != NULL && fseeko(of, url->offset, SEEK_SET) != 0) { + warn("%s: fseeko()", path); + fclose(of); + of = NULL; + /* picked up again later */ + } } else if (m_flag && sb.st_size != -1) { /* mirror mode, local file exists */ if (sb.st_size == us.size && sb.st_mtime == us.mtime) -- 2.45.0