ci/cron/check: use whileJust_ for recursion (#7747)

As suggested in #7746.

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Gary Verhaegen 2020-10-20 16:03:46 +02:00 committed by GitHub
parent 1d638c29cb
commit cdf6160c76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -19,8 +19,9 @@ da_haskell_binary(
"http-client", "http-client",
"http-client-tls", "http-client-tls",
"http-types", "http-types",
"optparse-applicative", "monad-loops",
"network-uri", "network-uri",
"optparse-applicative",
"process", "process",
"regex-tdfa", "regex-tdfa",
"semver", "semver",

View File

@ -12,6 +12,7 @@ import qualified Control.Concurrent.QSem
import qualified Control.Exception import qualified Control.Exception
import qualified Control.Monad as Control import qualified Control.Monad as Control
import qualified Control.Monad.Extra import qualified Control.Monad.Extra
import qualified Control.Monad.Loops
import qualified Data.Aeson as JSON import qualified Data.Aeson as JSON
import qualified Data.ByteString import qualified Data.ByteString
import qualified Data.ByteString.UTF8 as BS import qualified Data.ByteString.UTF8 as BS
@ -285,13 +286,11 @@ download_assets tmp release = do
HTTP.withResponse req manager (\resp -> do HTTP.withResponse req manager (\resp -> do
let body = HTTP.responseBody resp let body = HTTP.responseBody resp
IO.withBinaryFile (tmp </> (last $ Network.URI.pathSegments url)) IO.AppendMode (\handle -> do IO.withBinaryFile (tmp </> (last $ Network.URI.pathSegments url)) IO.AppendMode (\handle -> do
let loop = do while (readFrom body) (writeTo handle)))))
bs <- HTTP.brRead body where while = Control.Monad.Loops.whileJust_
if Data.ByteString.null bs then return () readFrom body = ifNotEmpty <$> HTTP.brRead body
else do ifNotEmpty bs = if Data.ByteString.null bs then Nothing else Just bs
Data.ByteString.hPut handle bs writeTo = Data.ByteString.hPut
loop
loop))))
verify_signatures :: FilePath -> FilePath -> String -> IO String verify_signatures :: FilePath -> FilePath -> String -> IO String
verify_signatures bash_lib tmp version_tag = do verify_signatures bash_lib tmp version_tag = do