aboutsummaryrefslogtreecommitdiff
path: root/Remote/S3real.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-05-15 02:49:43 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-05-15 03:38:08 -0400
commitcad0e1c8b7eb21f8dceca8dd9fa3bc1d1aa7eabd (patch)
treeb6be12dc1cc83a35ca7d89a862d85e6d71c38572 /Remote/S3real.hs
parentefa7f544050c0d5be6bc1b0fc0125278e475c213 (diff)
simplified a bunch of Maybe handling
Diffstat (limited to 'Remote/S3real.hs')
-rw-r--r--Remote/S3real.hs16
1 files changed, 6 insertions, 10 deletions
diff --git a/Remote/S3real.hs b/Remote/S3real.hs
index b0371eb5e..eaa6590b1 100644
--- a/Remote/S3real.hs
+++ b/Remote/S3real.hs
@@ -123,11 +123,7 @@ storeHelper (conn, bucket) r k file = do
content <- liftIO $ L.readFile file
-- size is provided to S3 so the whole content does not need to be
-- buffered to calculate it
- size <- case keySize k of
- Just s -> return $ fromIntegral s
- Nothing -> do
- s <- liftIO $ getFileStatus file
- return $ fileSize s
+ size <- maybe getsize (return . fromIntegral) $ keySize k
let object = setStorageClass storageclass $
S3Object bucket (show k) ""
[("Content-Length",(show size))] content
@@ -137,6 +133,9 @@ storeHelper (conn, bucket) r k file = do
case fromJust $ M.lookup "storageclass" $ fromJust $ config r of
"REDUCED_REDUNDANCY" -> REDUCED_REDUNDANCY
_ -> STANDARD
+ getsize = do
+ s <- liftIO $ getFileStatus file
+ return $ fileSize s
retrieve :: Remote Annex -> Key -> FilePath -> Annex Bool
retrieve r k f = s3Action r False $ \(conn, bucket) -> do
@@ -201,11 +200,8 @@ bucketKey :: String -> Key -> S3Object
bucketKey bucket k = S3Object bucket (show k) "" [] L.empty
s3ConnectionRequired :: RemoteConfig -> Annex AWSConnection
-s3ConnectionRequired c = do
- conn <- s3Connection c
- case conn of
- Nothing -> error "Cannot connect to S3"
- Just conn' -> return conn'
+s3ConnectionRequired c =
+ maybe (error "Cannot connect to S3") return =<< s3Connection c
s3Connection :: RemoteConfig -> Annex (Maybe AWSConnection)
s3Connection c = do