$OpenBSD: patch-Download_hs,v 1.6 2015/02/04 13:39:52 dcoppa Exp $

port to ghc-7.8

fix version number in the User-Agent string, and use full command
line switches for curl

--- Download.hs.orig	Tue Nov  8 09:49:38 2011
+++ Download.hs	Wed Feb  4 07:13:43 2015
@@ -43,7 +43,7 @@ import System.Posix.Process
 import System.Posix.Types
 import System.Posix.IO
 import Data.Hash.MD5
-import Control.Exception(evaluate)
+import qualified Control.Exception as E
 
 data Result = Success | Failure
             deriving (Eq, Show, Read)
@@ -59,14 +59,15 @@ d = debugM "download"
 i = infoM "download"
 
 curl = "curl"
-curlopts = ["-A", "hpodder v1.0.0; Haskell; GHC", -- Set User-Agent
-            "-s",               -- Silent mode
-            "-S",               -- Still show error messages
-            "-L",               -- Follow redirects
-            "-y", "60", "-Y", "1", -- Timeouts
-            "--retry", "2",     -- Retry twice
-            "--globoff",        -- Disable globbing on URLs (#79)
-            "-f"                -- Fail on server errors
+curlopts = ["--user-agent", "hpodder v1.1.6; Haskell; GHC", -- Set User-Agent
+            "--silent",           -- Silent mode
+            "--show-error",       -- Still show error messages
+            "--location",         -- Follow redirects
+            "--speed-limit", "1", -- Abort if slower than 1 byte per second
+            "--speed-time", "60", -- over more than 60 seconds
+            "--retry", "2",       -- Retry twice
+            "--globoff",          -- Disable globbing on URLs (#79)
+            "--fail"              -- Fail on server errors
            ]
 
 getCurlConfig :: IO String
@@ -74,7 +75,8 @@ getCurlConfig =
     do ad <- getAppDir
        return $ ad ++ "/curlrc"
 
-getsize fp = catch (getFileStatus fp >>= (return . Just . fileSize))
+getsize fp = (E.catch :: IO a -> (IOError -> IO a) -> IO a)
+             (getFileStatus fp >>= (return . Just . fileSize))
              (\_ -> return Nothing)
 
 {- | Begin the download process on the given URL.
@@ -87,8 +89,8 @@ startGetURL :: String           -- ^ URL to download
 startGetURL url dirbase allowresume =
     do curlrc <- getCurlConfig
        havecurlrc <- doesFileExist curlrc
-       let curlrcopts = (if havecurlrc then ["-K", curlrc] else [])
-                        ++ (if allowresume then ["-C", "-"] else [])
+       let curlrcopts = (if havecurlrc then ["--config", curlrc] else [])
+                        ++ (if allowresume then ["--continue-at", "-"] else [])
        let fp = dirbase ++ "/" ++ getdlfname url
        startsize <- getsize fp
        case startsize of 
@@ -99,7 +101,8 @@ startGetURL url dirbase allowresume =
                 (defaultFileFlags {trunc = True})
        msgfd2 <- dup msgfd
        pid <- pOpen3Raw Nothing (Just msgfd) (Just msgfd2) 
-                 curl (curlopts ++ curlrcopts ++ [url, "-o", fp])
+                 curl (curlopts ++ curlrcopts ++ [url, "--output", fp])
+
                  (return ())
        closeFd msgfd
        closeFd msgfd2
@@ -118,7 +121,7 @@ finishGetURL dltok ec =
        let r = case ec of
                   Exited ExitSuccess -> Success
                   Exited (ExitFailure i) -> Failure
-                  Terminated _ -> Failure
+                  Terminated _ _ -> Failure
                   Stopped _ -> Failure
        if r == Success
           then do d $ "curl returned successfully; new size is " ++
