summaryrefslogtreecommitdiff
path: root/Remote
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-07-15 12:47:14 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-07-15 12:47:14 -0400
commit6c396a256c93464d726c66a95132536941871ee8 (patch)
tree7f934c9eae22a9cfd3fb1672ebd7bf6870439c81 /Remote
parent185f0b687081f47d059cc0503f4f6b671868f753 (diff)
finished hlint pass
Diffstat (limited to 'Remote')
-rw-r--r--Remote/Bup.hs20
-rw-r--r--Remote/Directory.hs5
-rw-r--r--Remote/Encryptable.hs4
-rw-r--r--Remote/Git.hs6
-rw-r--r--Remote/Hook.hs16
-rw-r--r--Remote/Rsync.hs12
-rw-r--r--Remote/S3real.hs24
-rw-r--r--Remote/Special.hs2
-rw-r--r--Remote/Ssh.hs2
-rw-r--r--Remote/Web.hs4
10 files changed, 48 insertions, 47 deletions
diff --git a/Remote/Bup.hs b/Remote/Bup.hs
index 5a44397f0..4ea455226 100644
--- a/Remote/Bup.hs
+++ b/Remote/Bup.hs
@@ -8,7 +8,8 @@
module Remote.Bup (remote) where
import qualified Data.ByteString.Lazy.Char8 as L
-import IO
+import System.IO
+import System.IO.Error
import Control.Exception.Extensible (IOException)
import qualified Data.Map as M
import Control.Monad (when)
@@ -16,6 +17,7 @@ import Control.Monad.State (liftIO)
import System.Process
import System.Exit
import System.FilePath
+import Data.Maybe
import Data.List.Utils
import System.Cmd.Utils
@@ -68,7 +70,7 @@ gen r u c = do
bupSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
bupSetup u c = do
-- verify configuration is sane
- let buprepo = maybe (error "Specify buprepo=") id $
+ let buprepo = fromMaybe (error "Specify buprepo=") $
M.lookup "buprepo" c
c' <- encryptionSetup c
@@ -87,7 +89,7 @@ bupSetup u c = do
bupParams :: String -> BupRepo -> [CommandParam] -> [CommandParam]
bupParams command buprepo params =
- (Param command) : [Param "-r", Param buprepo] ++ params
+ Param command : [Param "-r", Param buprepo] ++ params
bup :: String -> BupRepo -> [CommandParam] -> Annex Bool
bup command buprepo params = do
@@ -123,8 +125,8 @@ storeEncrypted r buprepo (cipher, enck) k = do
g <- Annex.gitRepo
let src = gitAnnexLocation g k
params <- bupSplitParams r buprepo enck (Param "-")
- liftIO $ catchBool $ do
- withEncryptedHandle cipher (L.readFile src) $ \h -> do
+ liftIO $ catchBool $
+ withEncryptedHandle cipher (L.readFile src) $ \h ->
pipeBup params (Just h) Nothing
retrieve :: BupRepo -> Key -> FilePath -> Annex Bool
@@ -184,7 +186,7 @@ onBupRemote :: Git.Repo -> (FilePath -> [CommandParam] -> IO a) -> FilePath -> [
onBupRemote r a command params = do
let dir = shellEscape (Git.workTree r)
sshparams <- sshToRepo r [Param $
- "cd " ++ dir ++ " && " ++ (unwords $ command : toCommand params)]
+ "cd " ++ dir ++ " && " ++ unwords (command : toCommand params)]
liftIO $ a "ssh" sshparams
{- Allow for bup repositories on removable media by checking
@@ -215,20 +217,20 @@ bup2GitRemote "" = do
Git.repoFromAbsPath $ h </> ".bup"
bup2GitRemote r
| bupLocal r =
- if r !! 0 == '/'
+ if head r == '/'
then Git.repoFromAbsPath r
else error "please specify an absolute path"
| otherwise = Git.repoFromUrl $ "ssh://" ++ host ++ slash dir
where
bits = split ":" r
- host = bits !! 0
+ host = head bits
dir = join ":" $ drop 1 bits
-- "host:~user/dir" is not supported specially by bup;
-- "host:dir" is relative to the home directory;
-- "host:" goes in ~/.bup
slash d
| d == "" = "/~/.bup"
- | d !! 0 == '/' = d
+ | head d == '/' = d
| otherwise = "/~/" ++ d
bupLocal :: BupRepo -> Bool
diff --git a/Remote/Directory.hs b/Remote/Directory.hs
index 05d42136f..235f61300 100644
--- a/Remote/Directory.hs
+++ b/Remote/Directory.hs
@@ -8,13 +8,14 @@
module Remote.Directory (remote) where
import qualified Data.ByteString.Lazy.Char8 as L
-import IO
+import System.IO.Error
import Control.Exception.Extensible (IOException)
import qualified Data.Map as M
import Control.Monad (when)
import Control.Monad.State (liftIO)
import System.Directory hiding (copyFile)
import System.FilePath
+import Data.Maybe
import Types
import Types.Remote
@@ -60,7 +61,7 @@ gen r u c = do
directorySetup :: UUID -> RemoteConfig -> Annex RemoteConfig
directorySetup u c = do
-- verify configuration is sane
- let dir = maybe (error "Specify directory=") id $
+ let dir = fromMaybe (error "Specify directory=") $
M.lookup "directory" c
liftIO $ doesDirectoryExist dir
>>! error $ "Directory does not exist: " ++ dir
diff --git a/Remote/Encryptable.hs b/Remote/Encryptable.hs
index 443f5cf83..66e1738ac 100644
--- a/Remote/Encryptable.hs
+++ b/Remote/Encryptable.hs
@@ -56,10 +56,10 @@ encryptableRemote c storeKeyEncrypted retrieveKeyFileEncrypted r =
where
store k = cip k >>= maybe
(storeKey r k)
- (\x -> storeKeyEncrypted x k)
+ (`storeKeyEncrypted` k)
retrieve k f = cip k >>= maybe
(retrieveKeyFile r k f)
- (\x -> retrieveKeyFileEncrypted x f)
+ (`retrieveKeyFileEncrypted` f)
withkey a k = cip k >>= maybe (a k) (a . snd)
cip = cipherKey c
diff --git a/Remote/Git.hs b/Remote/Git.hs
index fb8512382..1f22ad11c 100644
--- a/Remote/Git.hs
+++ b/Remote/Git.hs
@@ -57,7 +57,7 @@ gen r u _ = do
let defcst = if cheap then cheapRemoteCost else expensiveRemoteCost
cst <- remoteCost r' defcst
- return $ Remote {
+ return Remote {
uuid = u',
cost = cst,
name = Git.repoDescribe r',
@@ -81,7 +81,7 @@ tryGitConfigRead r
-- Reading config can fail due to IO error or
-- for other reasons; catch all possible exceptions.
safely a = do
- result <- liftIO (try (a)::IO (Either SomeException Git.Repo))
+ result <- liftIO (try a :: IO (Either SomeException Git.Repo))
case result of
Left _ -> return r
Right r' -> return r'
@@ -154,7 +154,7 @@ copyToRemote r key
rsyncHelper =<< rsyncParamsRemote r False key keysrc
| otherwise = error "copying to non-ssh repo not supported"
-rsyncHelper :: [CommandParam] -> Annex (Bool)
+rsyncHelper :: [CommandParam] -> Annex Bool
rsyncHelper p = do
showProgress -- make way for progress bar
res <- liftIO $ rsync p
diff --git a/Remote/Hook.hs b/Remote/Hook.hs
index 86a7bca56..f0e4d5bfb 100644
--- a/Remote/Hook.hs
+++ b/Remote/Hook.hs
@@ -17,6 +17,7 @@ import System.Posix.IO
import System.IO
import System.IO.Error (try)
import System.Exit
+import Data.Maybe
import Types
import Types.Remote
@@ -61,7 +62,7 @@ gen r u c = do
hookSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
hookSetup u c = do
- let hooktype = maybe (error "Specify hooktype=") id $
+ let hooktype = fromMaybe (error "Specify hooktype=") $
M.lookup "hooktype" c
c' <- encryptionSetup c
gitConfigSpecialRemote u c' "hooktype" hooktype
@@ -73,12 +74,13 @@ hookEnv k f = Just $ fileenv f ++ keyenv
env s v = ("ANNEX_" ++ s, v)
keyenv =
[ env "KEY" (show k)
- , env "HASH_1" (hashbits !! 0)
- , env "HASH_2" (hashbits !! 1)
+ , env "HASH_1" hash_1
+ , env "HASH_2" hash_2
]
fileenv Nothing = []
fileenv (Just file) = [env "FILE" file]
- hashbits = map takeDirectory $ splitPath $ hashDirMixed k
+ [hash_1, hash_2, _rest] =
+ map takeDirectory $ splitPath $ hashDirMixed k
lookupHook :: String -> String -> Annex (Maybe String)
lookupHook hooktype hook =do
@@ -127,7 +129,7 @@ retrieveEncrypted h (cipher, enck) f = withTmp enck $ \tmp ->
return True
remove :: String -> Key -> Annex Bool
-remove h k = runHook h "remove" k Nothing $ do return True
+remove h k = runHook h "remove" k Nothing $ return True
checkPresent :: Git.Repo -> String -> Key -> Annex (Either IOException Bool)
checkPresent r h k = do
@@ -135,7 +137,7 @@ checkPresent r h k = do
v <- lookupHook h "checkpresent"
liftIO (try (check v) ::IO (Either IOException Bool))
where
- findkey s = (show k) `elem` (lines s)
+ findkey s = show k `elem` lines s
env = hookEnv k Nothing
check Nothing = error "checkpresent hook misconfigured"
check (Just hook) = do
@@ -150,5 +152,5 @@ checkPresent r h k = do
hClose fromh
s <- getProcessStatus True False pid
case s of
- Just (Exited (ExitSuccess)) -> return $ findkey reply
+ Just (Exited ExitSuccess) -> return $ findkey reply
_ -> error "checkpresent hook failed"
diff --git a/Remote/Rsync.hs b/Remote/Rsync.hs
index 80e194fed..ca4236276 100644
--- a/Remote/Rsync.hs
+++ b/Remote/Rsync.hs
@@ -15,6 +15,7 @@ import System.FilePath
import System.Directory
import System.Posix.Files
import System.Posix.Process
+import Data.Maybe
import Types
import Types.Remote
@@ -82,7 +83,7 @@ genRsyncOpts r = do
rsyncSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
rsyncSetup u c = do
-- verify configuration is sane
- let url = maybe (error "Specify rsyncurl=") id $
+ let url = fromMaybe (error "Specify rsyncurl=") $
M.lookup "rsyncurl" c
c' <- encryptionSetup c
@@ -160,10 +161,10 @@ partialParams = Params "--no-inplace --partial --partial-dir=.rsync-partial"
withRsyncScratchDir :: (FilePath -> Annex Bool) -> Annex Bool
withRsyncScratchDir a = do
g <- Annex.gitRepo
- pid <- liftIO $ getProcessID
+ pid <- liftIO getProcessID
let tmp = gitAnnexTmpDir g </> "rsynctmp" </> show pid
nuke tmp
- liftIO $ createDirectoryIfMissing True $ tmp
+ liftIO $ createDirectoryIfMissing True tmp
res <- a tmp
nuke tmp
return res
@@ -189,15 +190,14 @@ rsyncRemote o params = do
rsyncSend :: RsyncOpts -> Key -> FilePath -> Annex Bool
rsyncSend o k src = withRsyncScratchDir $ \tmp -> do
let dest = tmp </> hashDirMixed k </> f </> f
- liftIO $ createDirectoryIfMissing True $ parentDir $ dest
+ liftIO $ createDirectoryIfMissing True $ parentDir dest
liftIO $ createLink src dest
- res <- rsyncRemote o
+ rsyncRemote o
[ Param "--recursive"
, partialParams
-- tmp/ to send contents of tmp dir
, Param $ addTrailingPathSeparator tmp
, Param $ rsyncUrl o
]
- return res
where
f = keyFile k
diff --git a/Remote/S3real.hs b/Remote/S3real.hs
index 52d1ed1be..cbd3ef622 100644
--- a/Remote/S3real.hs
+++ b/Remote/S3real.hs
@@ -52,7 +52,7 @@ gen r u c = do
cst <- remoteCost r expensiveRemoteCost
return $ gen' r u c cst
gen' :: Git.Repo -> UUID -> Maybe RemoteConfig -> Int -> Remote Annex
-gen' r u c cst = do
+gen' r u c cst =
encryptableRemote c
(storeEncrypted this)
(retrieveEncrypted this)
@@ -85,7 +85,7 @@ s3Setup u c = handlehost $ M.lookup "host" c
handlehost Nothing = defaulthost
handlehost (Just h)
- | ".archive.org" `isSuffixOf` (map toLower h) = archiveorg
+ | ".archive.org" `isSuffixOf` map toLower h = archiveorg
| otherwise = defaulthost
use fullconfig = do
@@ -99,7 +99,7 @@ s3Setup u c = handlehost $ M.lookup "host" c
use fullconfig
archiveorg = do
- showNote $ "Internet Archive mode"
+ showNote "Internet Archive mode"
maybe (error "specify bucket=") (const $ return ()) $
M.lookup "bucket" archiveconfig
use archiveconfig
@@ -203,10 +203,8 @@ s3Error :: ReqError -> a
s3Error e = error $ prettyReqError e
s3Bool :: AWSResult () -> Annex Bool
-s3Bool res = do
- case res of
- Right _ -> return True
- Left e -> s3Warning e
+s3Bool (Right _) = return True
+s3Bool (Left e) = s3Warning e
s3Action :: Remote Annex -> a -> ((AWSConnection, String) -> Annex a) -> Annex a
s3Action r noconn action = do
@@ -219,7 +217,7 @@ s3Action r noconn action = do
_ -> return noconn
bucketFile :: Remote Annex -> Key -> FilePath
-bucketFile r k = (munge $ show k)
+bucketFile r = munge . show
where
munge s = case M.lookup "mungekeys" $ fromJust $ config r of
Just "ia" -> iaMunge s
@@ -271,8 +269,8 @@ s3Connection c = do
warning $ "Set both " ++ s3AccessKey ++ " and " ++ s3SecretKey ++ " to use S3"
return Nothing
where
- host = fromJust $ (M.lookup "host" c)
- port = let s = fromJust $ (M.lookup "port" c) in
+ host = fromJust $ M.lookup "host" c
+ port = let s = fromJust $ M.lookup "port" c in
case reads s of
[(p, _)] -> p
_ -> error $ "bad S3 port value: " ++ s
@@ -283,7 +281,7 @@ s3GetCreds :: RemoteConfig -> Annex (Maybe (String, String))
s3GetCreds c = do
ak <- getEnvKey s3AccessKey
sk <- getEnvKey s3SecretKey
- if (null ak || null sk)
+ if null ak || null sk
then do
mcipher <- remoteCipher c
case (M.lookup "s3creds" c, mcipher) of
@@ -291,9 +289,7 @@ s3GetCreds c = do
s <- liftIO $ withDecryptedContent cipher
(return $ L.pack $ fromB64 encrypted)
(return . L.unpack)
- let line = lines s
- let ak' = line !! 0
- let sk' = line !! 1
+ let [ak', sk', _rest] = lines s
liftIO $ do
setEnv s3AccessKey ak True
setEnv s3SecretKey sk True
diff --git a/Remote/Special.hs b/Remote/Special.hs
index 9a00dbd82..d6f362ce3 100644
--- a/Remote/Special.hs
+++ b/Remote/Special.hs
@@ -38,7 +38,7 @@ gitConfigSpecialRemote u c k v = do
g <- Annex.gitRepo
liftIO $ do
Git.run g "config" [Param (configsetting $ "annex-"++k), Param v]
- Git.run g "config" [Param (configsetting $ "annex-uuid"), Param u]
+ Git.run g "config" [Param (configsetting "annex-uuid"), Param u]
where
remotename = fromJust (M.lookup "name" c)
configsetting s = "remote." ++ remotename ++ "." ++ s
diff --git a/Remote/Ssh.hs b/Remote/Ssh.hs
index 0d4842a1a..fe4e6dfc1 100644
--- a/Remote/Ssh.hs
+++ b/Remote/Ssh.hs
@@ -39,7 +39,7 @@ git_annex_shell r command params
where
dir = Git.workTree r
shellcmd = "git-annex-shell"
- shellopts = (Param command):(File dir):params
+ shellopts = Param command : File dir : params
sshcmd = shellcmd ++ " " ++
unwords (map shellEscape $ toCommand shellopts)
diff --git a/Remote/Web.hs b/Remote/Web.hs
index d3d140d73..60f64cfe0 100644
--- a/Remote/Web.hs
+++ b/Remote/Web.hs
@@ -52,7 +52,7 @@ webUUID = "00000000-0000-0000-0000-000000000001"
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex (Remote Annex)
gen r _ _ =
- return $ Remote {
+ return Remote {
uuid = webUUID,
cost = expensiveRemoteCost,
name = Git.repoDescribe r,
@@ -111,7 +111,7 @@ checkKey' (u:us) = do
if e then return e else checkKey' us
urlexists :: URLString -> IO Bool
-urlexists url = do
+urlexists url =
case parseURI url of
Nothing -> return False
Just u -> do