Skip to content

Commit

Permalink
forwards compatibility with a warning if sha1 field is not present #637
Browse files Browse the repository at this point in the history
  • Loading branch information
DanBurton committed Jul 24, 2015
1 parent 947df47 commit 8812948
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ getSystemGHC menv = do
data DownloadInfo = DownloadInfo
{ downloadInfoUrl :: Text
, downloadInfoContentLength :: Int
, downloadInfoSha1 :: ByteString
, downloadInfoSha1 :: Maybe ByteString
}
deriving Show

Expand All @@ -350,11 +350,11 @@ parseDownloadInfoFromObject :: Yaml.Object -> Yaml.Parser DownloadInfo
parseDownloadInfoFromObject o = do
url <- o .: "url"
contentLength <- o .: "content-length"
sha1Text <- o .: "sha1"
sha1TextMay <- o .:? "sha1"
return DownloadInfo
{ downloadInfoUrl = url
, downloadInfoContentLength = contentLength
, downloadInfoSha1 = T.encodeUtf8 sha1Text
, downloadInfoSha1 = fmap T.encodeUtf8 sha1TextMay
}

instance FromJSON DownloadInfo where
Expand Down Expand Up @@ -753,11 +753,23 @@ chattyDownload label downloadInfo path = do
, T.pack $ toFilePath path
, " ..."
]

let sha1 = CheckHexDigestByteString (downloadInfoSha1 downloadInfo)
hashChecks <- case downloadInfoSha1 downloadInfo of
Just sha1ByteString -> do
let sha1 = CheckHexDigestByteString sha1ByteString
$logDebug $ T.concat
[ "Will check against sha1 hash: "
, T.decodeUtf8With T.lenientDecode sha1ByteString
]
return [HashCheck SHA1 sha1]
Nothing -> do
$logWarn $ T.concat
[ "No sha1 found in metadata,"
, " download hash won't be checked."
]
return []
let dReq = DownloadRequest
{ drRequest = req
, drHashChecks = [HashCheck SHA1 sha1]
, drHashChecks = hashChecks
, drLengthCheck = Just totalSize
, drRetryPolicy = drRetryPolicyDefault
}
Expand Down

0 comments on commit 8812948

Please sign in to comment.