when downloading same content from multiple urls, only display error if all fail
authorJoey Hess <joeyh@joeyh.name>
Wed, 2 Sep 2020 15:35:07 +0000 (11:35 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 2 Sep 2020 15:35:07 +0000 (11:35 -0400)
Annex/Content.hs

index ad0f62ed31f18ada3b72a9f9379afb245af8e89e..f3e7dad450ad2f95e477c83e75a08b6162d0c762 100644 (file)
@@ -807,8 +807,15 @@ downloadUrl :: Key -> MeterUpdate -> [Url.URLString] -> FilePath -> Url.UrlOptio
 downloadUrl k p urls file uo = 
        -- Poll the file to handle configurations where an external
        -- download command is used.
-       meteredFile file (Just p) k $
-               anyM (\u -> Url.download p u file uo) urls
+       meteredFile file (Just p) k (go urls Nothing)
+  where
+       -- Display only one error message, if all the urls fail to
+       -- download.
+       go [] (Just err) = warning err >> return False
+       go [] Nothing = return False
+       go (u:us) _ = Url.download' p u file uo >>= \case
+               Right () -> return True
+               Left err -> go us (Just err)
 
 {- Copies a key's content, when present, to a temp file.
  - This is used to speed up some rsyncs. -}