From 03af2efd4f6519c612b3354e7538c89b65e07691 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 4 Nov 2014 14:47:18 -0400 Subject: combine 2 checks --- Remote/S3.hs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'Remote/S3.hs') diff --git a/Remote/S3.hs b/Remote/S3.hs index b10585515..f19c42842 100644 --- a/Remote/S3.hs +++ b/Remote/S3.hs @@ -188,21 +188,21 @@ store r h = fileStorer $ \k f p -> do -- Send parts of the file, taking care to stream each part -- w/o buffering in memory, since the parts can be large. etags <- bracketIO (openBinaryFile f ReadMode) hClose $ \fh -> do - let sendparts meter etags partnum = ifM (liftIO $ hIsClosed fh) - ( return (reverse etags) - , do - pos <- liftIO $ hTell fh - -- Calculate size of part that will - -- be read. - let sz = if fsz - pos < partsz' - then fsz - pos - else partsz' - b <- liftIO $ hGetUntilMetered fh (< partsz') meter - let body = RequestBodyStream (fromIntegral sz) (mkPopper b) - S3.UploadPartResponse _ etag <- sendS3Handle h $ - S3.uploadPart (bucket info) object partnum uploadid body - sendparts (offsetMeterUpdate meter (toBytesProcessed sz)) (etag:etags) (partnum + 1) - ) + let sendparts meter etags partnum = do + pos <- liftIO $ hTell fh + if pos >= fsz + then return (reverse etags) + else do + -- Calculate size of part that will + -- be read. + let sz = if fsz - pos < partsz' + then fsz - pos + else partsz' + b <- liftIO $ hGetUntilMetered fh (< partsz') meter + let body = RequestBodyStream (fromIntegral sz) (mkPopper b) + S3.UploadPartResponse _ etag <- sendS3Handle h $ + S3.uploadPart (bucket info) object partnum uploadid body + sendparts (offsetMeterUpdate meter (toBytesProcessed sz)) (etag:etags) (partnum + 1) sendparts p [] 1 void $ sendS3Handle h $ S3.postCompleteMultipartUpload -- cgit v1.2.3