Improve error handling when getting uuid of http remotes to auto-ignore, like with ssh remotes.

This commit is contained in:
Joey Hess 2013-05-25 01:47:19 -04:00
parent b63d5e6b1d
commit e3c1586997
4 changed files with 42 additions and 36 deletions

View file

@ -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,