Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of compiler warnings #77

Merged
merged 3 commits into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,8 @@ uploadFrameworkToS3 frameworkArchive
s3BucketName
reverseRomeMap
(FrameworkVersion f@(FrameworkName fwn) version)
platform = do
(env, verbose) <- ask
runReaderT
(uploadBinary s3BucketName (Zip.fromArchive frameworkArchive) remoteFrameworkUploadPath fwn)
(env, verbose)
platform =
uploadBinary s3BucketName (Zip.fromArchive frameworkArchive) remoteFrameworkUploadPath fwn

where
remoteFrameworkUploadPath = remoteFrameworkPath platform reverseRomeMap f version
Expand All @@ -425,9 +422,8 @@ uploadDsymToS3 dSYMArchive
s3BucketName
reverseRomeMap
(FrameworkVersion f@(FrameworkName fwn) version)
platform = do
(env, verbose) <- ask
runReaderT (uploadBinary s3BucketName (Zip.fromArchive dSYMArchive) remoteDsymUploadPath (fwn ++ ".dSYM")) (env, verbose)
platform =
uploadBinary s3BucketName (Zip.fromArchive dSYMArchive) remoteDsymUploadPath (fwn ++ ".dSYM")

where
remoteDsymUploadPath = remoteDsymPath platform reverseRomeMap f version
Expand Down Expand Up @@ -611,6 +607,12 @@ zipDir dir verbose = do


-- | Uploads an artificat to an `S3.BucketName` at a given path in the bucket.
uploadBinary :: AWS.ToBody a
=> S3.BucketName
-> a
-> FilePath
-> FilePath
-> ReaderT (AWS.Env, Bool) IO ()
uploadBinary s3BucketName binaryZip destinationPath objectName = do
(env, verbose) <- ask
let objectKey = S3.ObjectKey $ T.pack destinationPath
Expand Down Expand Up @@ -1145,6 +1147,10 @@ getVersionFileFromS3 s3BucketName gitRepoNameAndVersion =


-- | Downloads an artificat stored at a given path from an `S3.BucketName`.
downloadBinary :: S3.BucketName
-> FilePath
-> FilePath
-> ExceptT String (ReaderT (AWS.Env, Bool) IO) LBS.ByteString
downloadBinary s3BucketName objectRemotePath objectName = do
(env, verbose) <- ask
runResourceT . AWS.runAWS env $ do
Expand All @@ -1164,12 +1170,11 @@ downloadBinary s3BucketName objectRemotePath objectName = do
printProgress :: MonadIO m => String -> Int -> C.Conduit BS.ByteString m BS.ByteString
printProgress objName totalLength = loop totalLength 0 0
where
roundedSizeInMB = roundBytesToMegabytes totalLength
loop t consumedLen lastLen = C.await >>= maybe (return ()) (\bs -> do
let len = consumedLen + BS.length bs
let diffGreaterThan1MB = len - lastLen >= 1024*1024
when ( diffGreaterThan1MB || len == t) $
sayLnWithTime $ "Downloaded " ++ show (roundBytesToMegabytes len) ++ " MB of " ++ show roundedSizeInMB ++ " MB for " ++ objName
sayLnWithTime $ "Downloaded " ++ showInMegabytes len ++ " of " ++ showInMegabytes totalLength ++ " for " ++ objName
C.yield bs
let a = if diffGreaterThan1MB then len else lastLen
loop t len a)
Expand Down
8 changes: 5 additions & 3 deletions src/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import qualified Network.AWS as AWS (Error, ErrorMessage (..),
_ServiceError)
import Network.HTTP.Conduit as HTTP
import Network.HTTP.Types.Header as HTTP (hUserAgent)
import Numeric (showFFloat)
import System.FilePath
import Text.Read (readMaybe)
import Types
Expand Down Expand Up @@ -97,10 +98,11 @@ sayLnWithTime line = do



-- | Given a number n representing bytes, gives an approximation in Megabytes.
roundBytesToMegabytes :: Integral n => n -> Double
roundBytesToMegabytes n = fromInteger (round (nInMB * (10^2))) / (10.0^^2)
-- | Given a number n representing bytes, shows it in MB, rounded to 2 decimal places.
showInMegabytes :: Integral n => n -> String
showInMegabytes n = showFFloat (Just 2) nInMB " MB"
where
nInMB :: Double
nInMB = fromIntegral n / (1024*1024)


Expand Down