From owner-svn-src-all@FreeBSD.ORG Tue Sep 27 15:57:13 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B2F291065673; Tue, 27 Sep 2011 15:57:13 +0000 (UTC) (envelope-from des@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A31FB8FC16; Tue, 27 Sep 2011 15:57:13 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p8RFvDDF030467; Tue, 27 Sep 2011 15:57:13 GMT (envelope-from des@svn.freebsd.org) Received: (from des@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p8RFvDZB030465; Tue, 27 Sep 2011 15:57:13 GMT (envelope-from des@svn.freebsd.org) Message-Id: <201109271557.p8RFvDZB030465@svn.freebsd.org> From: Dag-Erling Smorgrav Date: Tue, 27 Sep 2011 15:57:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225800 - head/usr.bin/fetch X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Sep 2011 15:57:13 -0000 Author: des Date: Tue Sep 27 15:57:13 2011 New Revision: 225800 URL: http://svn.freebsd.org/changeset/base/225800 Log: Followup to r225599: the fseek() was a no-op since the file was opened in append mode. Open it in read-write mode instead. Also move the fseek up one level to cover the (unlikely but not impossible) case where the server accepts ranges but does not send a Content-Size header. PR: bin/117277 MFC after: 3 weeks Modified: head/usr.bin/fetch/fetch.c Modified: head/usr.bin/fetch/fetch.c ============================================================================== --- head/usr.bin/fetch/fetch.c Tue Sep 27 15:08:59 2011 (r225799) +++ head/usr.bin/fetch/fetch.c Tue Sep 27 15:57:13 2011 (r225800) @@ -540,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; } @@ -559,13 +559,13 @@ fetch(char *URL, const char *path) sb = nsb; /* picked up again later */ } - /* seek to where we left off */ - if (of != NULL && fseek(of, url->offset, SEEK_SET) != 0) { - warn("%s: fseek()", path); - fclose(of); - of = NULL; - /* picked up again later */ - } + } + /* seek to where we left off */ + if (of != NULL && fseek(of, url->offset, SEEK_SET) != 0) { + warn("%s: fseek()", path); + fclose(of); + of = NULL; + /* picked up again later */ } } else if (m_flag && sb.st_size != -1) { /* mirror mode, local file exists */