From patchwork Sat Jun 30 21:43:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnout Vandecappelle X-Patchwork-Id: 168334 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ozlabs.org (Postfix) with ESMTP id F145D2C01BB for ; Sun, 1 Jul 2012 07:43:56 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id EAAEB8CD28; Sat, 30 Jun 2012 21:43:54 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id S9loWX4nQaIr; Sat, 30 Jun 2012 21:43:43 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id C55468CDA6; Sat, 30 Jun 2012 21:43:40 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 8C3738F753 for ; Sat, 30 Jun 2012 21:43:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 53FE38CD81 for ; Sat, 30 Jun 2012 21:43:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Il-V3+CSsHX1 for ; Sat, 30 Jun 2012 21:43:30 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from viper.mind.be (132.79-246-81.adsl-static.isp.belgacom.be [81.246.79.132]) by whitealder.osuosl.org (Postfix) with ESMTPS id 2B0978D8E8 for ; Sat, 30 Jun 2012 21:43:15 +0000 (UTC) Received: from [172.16.2.6] (helo=vandecaa-laptop) by viper.mind.be with esmtp (Exim 4.69) (envelope-from ) id 1Sl5Rb-0005YU-CC; Sat, 30 Jun 2012 23:43:13 +0200 Received: from arnout by vandecaa-laptop with local (Exim 4.80) (envelope-from ) id 1Sl5Rb-0003ht-3B; Sat, 30 Jun 2012 23:43:07 +0200 From: "Arnout Vandecappelle (Essensium/Mind)" To: buildroot@busybox.net Date: Sat, 30 Jun 2012 23:43:03 +0200 Message-Id: <1341092583-14212-1-git-send-email-arnout@mind.be> X-Mailer: git-send-email 1.7.10 Subject: [Buildroot] [PATCH] pkg-download: handle interrupted wget downloads X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: buildroot-bounces@busybox.net When a wget download is interrupted, the downloaded file is still created. It will therefore not be re-downloaded in the next build, and the extraction will fail. To avoid this, download to a temporary file first and rename when the download is successful. The existing mechanism doesn't work for interrupted downloads because the whole sub-shell is interrupted, so the rm-part never gets executed. Signed-off-by: Arnout Vandecappelle (Essensium/Mind) --- Note that using wget's -c option (continue an interrupted download) is not a good idea, because it refuses to do anything on servers that don't support the Range header. package/pkg-download.mk | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/package/pkg-download.mk b/package/pkg-download.mk index 7d1e543..7983706 100644 --- a/package/pkg-download.mk +++ b/package/pkg-download.mk @@ -158,11 +158,14 @@ endef # Download a file using wget. Only download the file if it doesn't # already exist in the download directory. If the download fails, # remove the file (because wget -O creates a 0-byte file even if the -# download fails). +# download fails). To handle an interrupted download as well, download +# to a temporary file first. The temporary file will be overwritten +# the next time the download is tried. define DOWNLOAD_WGET test -e $(DL_DIR)/$(2) || \ - $(WGET) -O $(DL_DIR)/$(2) '$(call qstrip,$(1))' || \ - (rm -f $(DL_DIR)/$(2) ; exit 1) + ($(WGET) -O $(DL_DIR)/$(2).tmp '$(call qstrip,$(1))' && \ + mv $(DL_DIR)/$(2).tmp $(DL_DIR)/$(2)) || \ + (rm -f $(DL_DIR)/$(2).tmp ; exit 1) endef define SOURCE_CHECK_WGET