aboutsummaryrefslogtreecommitdiff
path: root/Utility/Url.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-10-11 13:05:00 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-10-11 13:05:00 -0400
commite55273da750678b4aa2dd6257a5ca7d8de81c755 (patch)
tree5808d49703687ec5ad695b459233bb1b9d8073f3 /Utility/Url.hs
parent108372d7ca8159264a046992a4467d2460add529 (diff)
url size fixes
addurl: Improve message when adding url with wrong size to existing file. Before the message suggested the url didn't exist. Fixed handling of URL keys that have no recorded size. Before, if the key has no size, the url also had to not declare any size, which was unlikely and wrong, or it was taken to not exist. This probably would mostly affect keys that were added to the annex with addurl --relaxed.
Diffstat (limited to 'Utility/Url.hs')
-rw-r--r--Utility/Url.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/Utility/Url.hs b/Utility/Url.hs
index baea0fda1..97296c920 100644
--- a/Utility/Url.hs
+++ b/Utility/Url.hs
@@ -11,6 +11,7 @@ module Utility.Url (
URLString,
UserAgent,
check,
+ checkBoth,
exists,
download,
downloadQuiet
@@ -32,12 +33,18 @@ type UserAgent = String
{- Checks that an url exists and could be successfully downloaded,
- also checking that its size, if available, matches a specified size. -}
-check :: URLString -> Headers -> Maybe Integer -> Maybe UserAgent -> IO Bool
+checkBoth :: URLString -> Headers -> Maybe Integer -> Maybe UserAgent -> IO Bool
+checkBoth url headers expected_size ua = do
+ v <- check url headers expected_size ua
+ return (fst v && snd v)
+check :: URLString -> Headers -> Maybe Integer -> Maybe UserAgent -> IO (Bool, Bool)
check url headers expected_size = handle <$$> exists url headers
where
- handle (False, _) = False
- handle (True, Nothing) = True
- handle (True, s) = expected_size == s
+ handle (False, _) = (False, False)
+ handle (True, Nothing) = (True, True)
+ handle (True, s) = case expected_size of
+ Just _ -> (True, expected_size == s)
+ Nothing -> (True, True)
{- Checks that an url exists and could be successfully downloaded,
- also returning its size if available.