Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Oct 2011 12:14:14 +0000 (UTC)
From:      Dag-Erling Smorgrav <des@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r226540 - stable/8/usr.bin/fetch
Message-ID:  <201110191214.p9JCEEmp024264@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: des
Date: Wed Oct 19 12:14:14 2011
New Revision: 226540
URL: http://svn.freebsd.org/changeset/base/226540

Log:
  MFH r225599,225800,225805: improve handling of resumed http transfers
  
  PR:		bin/117277

Modified:
  stable/8/usr.bin/fetch/fetch.c
Directory Properties:
  stable/8/usr.bin/fetch/   (props changed)

Modified: stable/8/usr.bin/fetch/fetch.c
==============================================================================
--- stable/8/usr.bin/fetch/fetch.c	Wed Oct 19 11:49:14 2011	(r226539)
+++ stable/8/usr.bin/fetch/fetch.c	Wed Oct 19 12:14:14 2011	(r226540)
@@ -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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201110191214.p9JCEEmp024264>