simplified a bunch of Maybe handling
This commit is contained in:
parent
efa7f54405
commit
cad0e1c8b7
19 changed files with 81 additions and 140 deletions
|
@ -68,9 +68,8 @@ gen r u c = do
|
|||
bupSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||
bupSetup u c = do
|
||||
-- verify configuration is sane
|
||||
let buprepo = case M.lookup "buprepo" c of
|
||||
Nothing -> error "Specify buprepo="
|
||||
Just r -> r
|
||||
let buprepo = maybe (error "Specify buprepo=") id $
|
||||
M.lookup "buprepo" c
|
||||
c' <- encryptionSetup c
|
||||
|
||||
-- bup init will create the repository.
|
||||
|
|
|
@ -60,9 +60,8 @@ gen r u c = do
|
|||
directorySetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||
directorySetup u c = do
|
||||
-- verify configuration is sane
|
||||
let dir = case M.lookup "directory" c of
|
||||
Nothing -> error "Specify directory="
|
||||
Just d -> d
|
||||
let dir = maybe (error "Specify directory=") id $
|
||||
M.lookup "directory" c
|
||||
e <- liftIO $ doesDirectoryExist dir
|
||||
when (not e) $ error $ "Directory does not exist: " ++ dir
|
||||
c' <- encryptionSetup c
|
||||
|
|
|
@ -73,11 +73,10 @@ encryptableRemote c storeKeyEncrypted retrieveKeyFileEncrypted r =
|
|||
{- Gets encryption Cipher. The decrypted Cipher is cached in the Annex
|
||||
- state. -}
|
||||
remoteCipher :: RemoteConfig -> Annex (Maybe Cipher)
|
||||
remoteCipher c = do
|
||||
cache <- Annex.getState Annex.cipher
|
||||
case cache of
|
||||
Just cipher -> return $ Just cipher
|
||||
Nothing -> case extractCipher c of
|
||||
remoteCipher c = maybe expensive cached =<< Annex.getState Annex.cipher
|
||||
where
|
||||
cached cipher = return $ Just cipher
|
||||
expensive = case extractCipher c of
|
||||
Nothing -> return Nothing
|
||||
Just encipher -> do
|
||||
showNote "gpg"
|
||||
|
|
|
@ -61,9 +61,8 @@ gen r u c = do
|
|||
|
||||
hookSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||
hookSetup u c = do
|
||||
let hooktype = case M.lookup "hooktype" c of
|
||||
Nothing -> error "Specify hooktype="
|
||||
Just r -> r
|
||||
let hooktype = maybe (error "Specify hooktype=") id $
|
||||
M.lookup "hooktype" c
|
||||
c' <- encryptionSetup c
|
||||
gitConfigSpecialRemote u c' "hooktype" hooktype
|
||||
return c'
|
||||
|
@ -94,14 +93,12 @@ lookupHook hooktype hook =do
|
|||
hookname = hooktype ++ "-" ++ hook ++ "-hook"
|
||||
|
||||
runHook :: String -> String -> Key -> Maybe FilePath -> Annex Bool -> Annex Bool
|
||||
runHook hooktype hook k f a = do
|
||||
command <- lookupHook hooktype hook
|
||||
case command of
|
||||
Nothing -> return False
|
||||
Just c -> do
|
||||
runHook hooktype hook k f a = maybe (return False) run =<< lookupHook hooktype hook
|
||||
where
|
||||
run command = do
|
||||
showProgress -- make way for hook output
|
||||
res <- liftIO $ boolSystemEnv
|
||||
"sh" [Param "-c", Param c] $ hookEnv k f
|
||||
"sh" [Param "-c", Param command] $ hookEnv k f
|
||||
if res
|
||||
then a
|
||||
else do
|
||||
|
|
|
@ -82,9 +82,8 @@ genRsyncOpts r = do
|
|||
rsyncSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||
rsyncSetup u c = do
|
||||
-- verify configuration is sane
|
||||
let url = case M.lookup "rsyncurl" c of
|
||||
Nothing -> error "Specify rsyncurl="
|
||||
Just d -> d
|
||||
let url = maybe (error "Specify rsyncurl=") id $
|
||||
M.lookup "rsyncurl" c
|
||||
c' <- encryptionSetup c
|
||||
|
||||
-- The rsyncurl is stored in git config, not only in this remote's
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue