diff options
author | Joey Hess <joey@kitenet.net> | 2013-05-25 01:47:19 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-05-25 01:47:19 -0400 |
commit | 6442bc73b2799c46c8a45a3cd265dd8dfeaea1f3 (patch) | |
tree | 8aad7bd4296a8e57d9a531f08ccc7310e8c98fab /Utility | |
parent | b22331137b23da2770354990602c7727a083101c (diff) |
Improve error handling when getting uuid of http remotes to auto-ignore, like with ssh remotes.
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/Url.hs | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/Utility/Url.hs b/Utility/Url.hs index b831b3f01..e08266a76 100644 --- a/Utility/Url.hs +++ b/Utility/Url.hs @@ -12,7 +12,7 @@ module Utility.Url ( check, exists, download, - get + downloadQuiet ) where import Common @@ -91,7 +91,14 @@ exists url headers = case parseURIRelaxed url of - for only one in. -} download :: URLString -> Headers -> [CommandParam] -> FilePath -> IO Bool -download url headers options file = +download = download' False + +{- No output, even on error. -} +downloadQuiet :: URLString -> Headers -> [CommandParam] -> FilePath -> IO Bool +downloadQuiet = download' True + +download' :: Bool -> URLString -> Headers -> [CommandParam] -> FilePath -> IO Bool +download' quiet url headers options file = case parseURIRelaxed url of Just u | uriScheme u == "file:" -> do @@ -103,31 +110,18 @@ download url headers options file = _ -> return False where headerparams = map (\h -> Param $ "--header=" ++ h) headers - wget = go "wget" $ headerparams ++ [Params "-c -O"] + wget = go "wget" $ headerparams ++ quietopt "-q" ++ [Params "-c -O"] {- Uses the -# progress display, because the normal - one is very confusing when resuming, showing - the remainder to download as the whole file, - and not indicating how much percent was - downloaded before the resume. -} - curl = go "curl" $ headerparams ++ [Params "-L -C - -# -o"] + curl = go "curl" $ headerparams ++ quietopt "-s" ++ [Params "-L -C - -# -o"] go cmd opts = boolSystem cmd $ options++opts++[File file, File url] - -{- Downloads a small file. - - - - Uses curl if available since it handles HTTPS better than - - the Haskell libraries do. -} -get :: URLString -> Headers -> IO String -get url headers = if Build.SysConfig.curl - then readProcess "curl" $ - ["-s", "-L", url] ++ concatMap (\h -> ["-H", h]) headers - else case parseURI url of - Nothing -> error "url parse error" - Just u -> do - r <- request u headers GET - case rspCode r of - (2,_,_) -> return $ rspBody r - _ -> error $ rspReason r + quietopt s + | quiet = [Param s] + | otherwise = [] {- Uses Network.Browser to make a http request of an url. - For example, HEAD can be used to check if the url exists, |