From fd48e801d29adc327fd943e849651b9c85cd7320 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Domen=20Ko=C5=BEar?= <domen@dev.si>
Date: Wed, 1 Oct 2014 13:58:42 +0200
Subject: [PATCH] fetchurl: resume download of curl exits with status code 18

---
 pkgs/build-support/fetchurl/builder.sh | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/pkgs/build-support/fetchurl/builder.sh b/pkgs/build-support/fetchurl/builder.sh
index 0c6e16551b4a..48881bdb2844 100644
--- a/pkgs/build-support/fetchurl/builder.sh
+++ b/pkgs/build-support/fetchurl/builder.sh
@@ -25,8 +25,16 @@ tryDownload() {
     local url="$1"
     echo
     header "trying $url"
+    local curlexit=18;
+
+    # if we get error code 18, resume partial download
+    while [ $curlexit -eq 18 ]; do
+        $curl -C - --fail "$url" --output "$downloadedFile"
+        local curlexit=$?;
+    done
+
     success=
-    if $curl --fail "$url" --output "$downloadedFile"; then
+    if [ $curlexit -eq 0 ]; then
         success=1
     fi
     stopNest