summaryrefslogtreecommitdiff
path: root/Remote/S3.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-11-04 14:47:18 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-11-04 14:47:18 -0400
commit03af2efd4f6519c612b3354e7538c89b65e07691 (patch)
treed2693c33537b7500124b82d7dd1f481504be413b /Remote/S3.hs
parenta86e452560999403a792db8dc4841dbeb1e7194a (diff)
combine 2 checks
Diffstat (limited to 'Remote/S3.hs')
-rw-r--r--Remote/S3.hs30
1 files changed, 15 insertions, 15 deletions
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