When checking that an url has a key, verify that the Content-Length, if available, matches the size of the key.

If there's no Content-Length, or the key has no size, this check is not
done, but it should happen most of the time, and protect against web
content that has changed.
This commit is contained in:
Joey Hess 2012-02-10 19:17:41 -04:00
parent fa77d9486d
commit 9030f68452
5 changed files with 30 additions and 11 deletions

View file

@ -15,6 +15,7 @@ import Annex.Content
import Config
import Logs.Web
import qualified Utility.Url as Url
import Types.Key
remote :: RemoteType
remote = RemoteType {
@ -77,8 +78,8 @@ checkKey key = do
us <- getUrls key
if null us
then return $ Right False
else return . Right =<< checkKey' us
checkKey' :: [URLString] -> Annex Bool
checkKey' us = untilTrue us $ \u -> do
else return . Right =<< checkKey' key us
checkKey' :: Key -> [URLString] -> Annex Bool
checkKey' key us = untilTrue us $ \u -> do
showAction $ "checking " ++ u
liftIO $ Url.exists u
liftIO $ Url.check u (keySize key)