simplified a bunch of Maybe handling
This commit is contained in:
parent
efa7f54405
commit
cad0e1c8b7
19 changed files with 81 additions and 140 deletions
29
Backend.hs
29
Backend.hs
|
@ -76,10 +76,9 @@ list = do
|
||||||
|
|
||||||
{- Looks up a backend in a list. May fail if unknown. -}
|
{- Looks up a backend in a list. May fail if unknown. -}
|
||||||
lookupBackendName :: [Backend Annex] -> String -> Backend Annex
|
lookupBackendName :: [Backend Annex] -> String -> Backend Annex
|
||||||
lookupBackendName bs s =
|
lookupBackendName bs s = maybe unknown id $ maybeLookupBackendName bs s
|
||||||
case maybeLookupBackendName bs s of
|
where
|
||||||
Just b -> b
|
unknown = error $ "unknown backend " ++ s
|
||||||
Nothing -> error $ "unknown backend " ++ s
|
|
||||||
maybeLookupBackendName :: [Backend Annex] -> String -> Maybe (Backend Annex)
|
maybeLookupBackendName :: [Backend Annex] -> String -> Maybe (Backend Annex)
|
||||||
maybeLookupBackendName bs s =
|
maybeLookupBackendName bs s =
|
||||||
if 1 /= length matches
|
if 1 /= length matches
|
||||||
|
@ -91,23 +90,18 @@ maybeLookupBackendName bs s =
|
||||||
storeFileKey :: FilePath -> Maybe (Backend Annex) -> Annex (Maybe (Key, Backend Annex))
|
storeFileKey :: FilePath -> Maybe (Backend Annex) -> Annex (Maybe (Key, Backend Annex))
|
||||||
storeFileKey file trybackend = do
|
storeFileKey file trybackend = do
|
||||||
bs <- list
|
bs <- list
|
||||||
let bs' = case trybackend of
|
let bs' = maybe bs (:bs) trybackend
|
||||||
Nothing -> bs
|
|
||||||
Just backend -> backend:bs
|
|
||||||
storeFileKey' bs' file
|
storeFileKey' bs' file
|
||||||
storeFileKey' :: [Backend Annex] -> FilePath -> Annex (Maybe (Key, Backend Annex))
|
storeFileKey' :: [Backend Annex] -> FilePath -> Annex (Maybe (Key, Backend Annex))
|
||||||
storeFileKey' [] _ = return Nothing
|
storeFileKey' [] _ = return Nothing
|
||||||
storeFileKey' (b:bs) file = do
|
storeFileKey' (b:bs) file = maybe nextbackend store =<< (B.getKey b) file
|
||||||
result <- (B.getKey b) file
|
where
|
||||||
case result of
|
nextbackend = storeFileKey' bs file
|
||||||
Nothing -> nextbackend
|
store key = do
|
||||||
Just key -> do
|
|
||||||
stored <- (B.storeFileKey b) file key
|
stored <- (B.storeFileKey b) file key
|
||||||
if (not stored)
|
if (not stored)
|
||||||
then nextbackend
|
then nextbackend
|
||||||
else return $ Just (key, b)
|
else return $ Just (key, b)
|
||||||
where
|
|
||||||
nextbackend = storeFileKey' bs file
|
|
||||||
|
|
||||||
{- Attempts to retrieve an key from one of the backends, saving it to
|
{- Attempts to retrieve an key from one of the backends, saving it to
|
||||||
- a specified location. -}
|
- a specified location. -}
|
||||||
|
@ -148,11 +142,8 @@ lookupFile file = do
|
||||||
getsymlink = do
|
getsymlink = do
|
||||||
l <- readSymbolicLink file
|
l <- readSymbolicLink file
|
||||||
return $ takeFileName l
|
return $ takeFileName l
|
||||||
makekey bs l =
|
makekey bs l = maybe (return Nothing) (makeret bs l) (fileKey l)
|
||||||
case fileKey l of
|
makeret bs l k =
|
||||||
Just k -> makeret k l bs
|
|
||||||
Nothing -> return Nothing
|
|
||||||
makeret k l bs =
|
|
||||||
case maybeLookupBackendName bs bname of
|
case maybeLookupBackendName bs bname of
|
||||||
Just backend -> return $ Just (k, backend)
|
Just backend -> return $ Just (k, backend)
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
|
|
|
@ -14,7 +14,5 @@ toB64 :: String -> String
|
||||||
toB64 = encode . s2w8
|
toB64 = encode . s2w8
|
||||||
|
|
||||||
fromB64 :: String -> String
|
fromB64 :: String -> String
|
||||||
fromB64 s =
|
fromB64 s = maybe bad w82s $ decode s
|
||||||
case decode s of
|
where bad = error "bad base64 encoded data"
|
||||||
Nothing -> error "bad base64 encoded data"
|
|
||||||
Just ws -> w82s ws
|
|
||||||
|
|
26
Command.hs
26
Command.hs
|
@ -14,6 +14,7 @@ import Control.Monad (filterM, liftM, when)
|
||||||
import System.Path.WildMatch
|
import System.Path.WildMatch
|
||||||
import Text.Regex.PCRE.Light.Char8
|
import Text.Regex.PCRE.Light.Char8
|
||||||
import Data.List
|
import Data.List
|
||||||
|
import Data.Maybe
|
||||||
|
|
||||||
import Types
|
import Types
|
||||||
import qualified Backend
|
import qualified Backend
|
||||||
|
@ -106,18 +107,10 @@ doCommand start = do
|
||||||
return c
|
return c
|
||||||
|
|
||||||
notAnnexed :: FilePath -> Annex (Maybe a) -> Annex (Maybe a)
|
notAnnexed :: FilePath -> Annex (Maybe a) -> Annex (Maybe a)
|
||||||
notAnnexed file a = do
|
notAnnexed file a = maybe a (const $ return Nothing) =<< Backend.lookupFile file
|
||||||
r <- Backend.lookupFile file
|
|
||||||
case r of
|
|
||||||
Just _ -> return Nothing
|
|
||||||
Nothing -> a
|
|
||||||
|
|
||||||
isAnnexed :: FilePath -> ((Key, Backend Annex) -> Annex (Maybe a)) -> Annex (Maybe a)
|
isAnnexed :: FilePath -> ((Key, Backend Annex) -> Annex (Maybe a)) -> Annex (Maybe a)
|
||||||
isAnnexed file a = do
|
isAnnexed file a = maybe (return Nothing) a =<< Backend.lookupFile file
|
||||||
r <- Backend.lookupFile file
|
|
||||||
case r of
|
|
||||||
Just v -> a v
|
|
||||||
Nothing -> return Nothing
|
|
||||||
|
|
||||||
notBareRepo :: Annex a -> Annex a
|
notBareRepo :: Annex a -> Annex a
|
||||||
notBareRepo a = do
|
notBareRepo a = do
|
||||||
|
@ -183,9 +176,7 @@ withFilesUnlocked' typechanged a params = do
|
||||||
withKeys :: CommandSeekKeys
|
withKeys :: CommandSeekKeys
|
||||||
withKeys a params = return $ map a $ map parse params
|
withKeys a params = return $ map a $ map parse params
|
||||||
where
|
where
|
||||||
parse p = case readKey p of
|
parse p = maybe (error "bad key") id $ readKey p
|
||||||
Just k -> k
|
|
||||||
Nothing -> error "bad key"
|
|
||||||
withTempFile :: CommandSeekStrings
|
withTempFile :: CommandSeekStrings
|
||||||
withTempFile a params = return $ map a params
|
withTempFile a params = return $ map a params
|
||||||
withNothing :: CommandSeekNothing
|
withNothing :: CommandSeekNothing
|
||||||
|
@ -206,9 +197,7 @@ filterFiles l = do
|
||||||
else return $ filter (notExcluded $ wildsRegex exclude) l'
|
else return $ filter (notExcluded $ wildsRegex exclude) l'
|
||||||
where
|
where
|
||||||
notState f = not $ stateDir `isPrefixOf` f
|
notState f = not $ stateDir `isPrefixOf` f
|
||||||
notExcluded r f = case match r f [] of
|
notExcluded r f = isJust $ match r f []
|
||||||
Nothing -> True
|
|
||||||
Just _ -> False
|
|
||||||
|
|
||||||
wildsRegex :: [String] -> Regex
|
wildsRegex :: [String] -> Regex
|
||||||
wildsRegex ws = compile regex []
|
wildsRegex ws = compile regex []
|
||||||
|
@ -257,11 +246,10 @@ cmdlineKey = do
|
||||||
case k of
|
case k of
|
||||||
Nothing -> nokey
|
Nothing -> nokey
|
||||||
Just "" -> nokey
|
Just "" -> nokey
|
||||||
Just kstring -> case readKey kstring of
|
Just kstring -> maybe badkey return $ readKey kstring
|
||||||
Nothing -> error "bad key"
|
|
||||||
Just key -> return key
|
|
||||||
where
|
where
|
||||||
nokey = error "please specify the key with --key"
|
nokey = error "please specify the key with --key"
|
||||||
|
badkey = error "bad key"
|
||||||
|
|
||||||
{- Given an original list of files, and an expanded list derived from it,
|
{- Given an original list of files, and an expanded list derived from it,
|
||||||
- ensures that the original list's ordering is preserved.
|
- ensures that the original list's ordering is preserved.
|
||||||
|
|
|
@ -58,14 +58,13 @@ start (unused, unusedbad, unusedtmp) s = notBareRepo $ search
|
||||||
next $ a key
|
next $ a key
|
||||||
|
|
||||||
perform :: Key -> CommandPerform
|
perform :: Key -> CommandPerform
|
||||||
perform key = do
|
perform key = maybe droplocal dropremote =<< Annex.getState Annex.fromremote
|
||||||
from <- Annex.getState Annex.fromremote
|
where
|
||||||
case from of
|
dropremote name = do
|
||||||
Just name -> do
|
|
||||||
r <- Remote.byName name
|
r <- Remote.byName name
|
||||||
showNote $ "from " ++ Remote.name r ++ "..."
|
showNote $ "from " ++ Remote.name r ++ "..."
|
||||||
next $ Command.Move.fromCleanup r True key
|
next $ Command.Move.fromCleanup r True key
|
||||||
_ -> do
|
droplocal = do
|
||||||
backend <- keyBackend key
|
backend <- keyBackend key
|
||||||
Command.Drop.perform key backend (Just 0) -- force drop
|
Command.Drop.perform key backend (Just 0) -- force drop
|
||||||
|
|
||||||
|
|
|
@ -68,11 +68,11 @@ cleanup u c = do
|
||||||
findByName :: String -> Annex (UUID, RemoteClass.RemoteConfig)
|
findByName :: String -> Annex (UUID, RemoteClass.RemoteConfig)
|
||||||
findByName name = do
|
findByName name = do
|
||||||
m <- Remote.readRemoteLog
|
m <- Remote.readRemoteLog
|
||||||
case findByName' name m of
|
maybe generate return $ findByName' name m
|
||||||
Just i -> return i
|
where
|
||||||
Nothing -> do
|
generate = do
|
||||||
uuid <- liftIO $ genUUID
|
uuid <- liftIO $ genUUID
|
||||||
return $ (uuid, M.insert nameKey name M.empty)
|
return (uuid, M.insert nameKey name M.empty)
|
||||||
|
|
||||||
findByName' :: String -> M.Map UUID RemoteClass.RemoteConfig -> Maybe (UUID, RemoteClass.RemoteConfig)
|
findByName' :: String -> M.Map UUID RemoteClass.RemoteConfig -> Maybe (UUID, RemoteClass.RemoteConfig)
|
||||||
findByName' n m = if null matches then Nothing else Just $ head matches
|
findByName' n m = if null matches then Nothing else Just $ head matches
|
||||||
|
@ -86,12 +86,13 @@ findByName' n m = if null matches then Nothing else Just $ head matches
|
||||||
|
|
||||||
{- find the specified remote type -}
|
{- find the specified remote type -}
|
||||||
findType :: RemoteClass.RemoteConfig -> Annex (RemoteClass.RemoteType Annex)
|
findType :: RemoteClass.RemoteConfig -> Annex (RemoteClass.RemoteType Annex)
|
||||||
findType config =
|
findType config = maybe unspecified specified $ M.lookup typeKey config
|
||||||
case M.lookup typeKey config of
|
where
|
||||||
Nothing -> error "Specify the type of remote with type="
|
unspecified = error "Specify the type of remote with type="
|
||||||
Just s -> case filter (\i -> RemoteClass.typename i == s) Remote.remoteTypes of
|
specified s = case filter (findtype s) Remote.remoteTypes of
|
||||||
[] -> error $ "Unknown remote type " ++ s
|
[] -> error $ "Unknown remote type " ++ s
|
||||||
(t:_) -> return t
|
(t:_) -> return t
|
||||||
|
findtype s i = RemoteClass.typename i == s
|
||||||
|
|
||||||
{- The name of a configured remote is stored in its config using this key. -}
|
{- The name of a configured remote is stored in its config using this key. -}
|
||||||
nameKey :: String
|
nameKey :: String
|
||||||
|
|
|
@ -84,10 +84,7 @@ repoName umap r
|
||||||
| otherwise = M.findWithDefault fallback repouuid umap
|
| otherwise = M.findWithDefault fallback repouuid umap
|
||||||
where
|
where
|
||||||
repouuid = getUncachedUUID r
|
repouuid = getUncachedUUID r
|
||||||
fallback =
|
fallback = maybe "unknown" id $ Git.repoRemoteName r
|
||||||
case (Git.repoRemoteName r) of
|
|
||||||
Just n -> n
|
|
||||||
Nothing -> "unknown"
|
|
||||||
|
|
||||||
{- A unique id for the node for a repo. Uses the annex.uuid if available. -}
|
{- A unique id for the node for a repo. Uses the annex.uuid if available. -}
|
||||||
nodeId :: Git.Repo -> String
|
nodeId :: Git.Repo -> String
|
||||||
|
@ -121,13 +118,10 @@ edge umap fullinfo from to =
|
||||||
{- Only name an edge if the name is different than the name
|
{- Only name an edge if the name is different than the name
|
||||||
- that will be used for the destination node, and is
|
- that will be used for the destination node, and is
|
||||||
- different from its hostname. (This reduces visual clutter.) -}
|
- different from its hostname. (This reduces visual clutter.) -}
|
||||||
edgename =
|
edgename = maybe Nothing calcname $ Git.repoRemoteName to
|
||||||
case (Git.repoRemoteName to) of
|
calcname n
|
||||||
Nothing -> Nothing
|
| n == repoName umap fullto || n == hostname fullto = Nothing
|
||||||
Just n ->
|
| otherwise = Just n
|
||||||
if (n == repoName umap fullto || n == hostname fullto)
|
|
||||||
then Nothing
|
|
||||||
else Just n
|
|
||||||
|
|
||||||
unreachable :: String -> String
|
unreachable :: String -> String
|
||||||
unreachable = Dot.fillColor "red"
|
unreachable = Dot.fillColor "red"
|
||||||
|
|
|
@ -41,12 +41,7 @@ start = notBareRepo $ do
|
||||||
|
|
||||||
perform :: CommandPerform
|
perform :: CommandPerform
|
||||||
perform = do
|
perform = do
|
||||||
from <- Annex.getState Annex.fromremote
|
maybe checkUnused checkRemoteUnused =<< Annex.getState Annex.fromremote
|
||||||
case from of
|
|
||||||
Just name -> do
|
|
||||||
r <- Remote.byName name
|
|
||||||
checkRemoteUnused r
|
|
||||||
_ -> checkUnused
|
|
||||||
next $ return True
|
next $ return True
|
||||||
|
|
||||||
checkUnused :: Annex ()
|
checkUnused :: Annex ()
|
||||||
|
@ -63,8 +58,11 @@ checkUnused = do
|
||||||
writeUnusedFile file unusedlist
|
writeUnusedFile file unusedlist
|
||||||
return $ length l
|
return $ length l
|
||||||
|
|
||||||
checkRemoteUnused :: Remote.Remote Annex -> Annex ()
|
checkRemoteUnused :: String -> Annex ()
|
||||||
checkRemoteUnused r = do
|
checkRemoteUnused name = checkRemoteUnused' =<< Remote.byName name
|
||||||
|
|
||||||
|
checkRemoteUnused' :: Remote.Remote Annex -> Annex ()
|
||||||
|
checkRemoteUnused' r = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
showNote $ "checking for unused data on " ++ Remote.name r ++ "..."
|
showNote $ "checking for unused data on " ++ Remote.name r ++ "..."
|
||||||
referenced <- getKeysReferenced
|
referenced <- getKeysReferenced
|
||||||
|
|
10
Content.hs
10
Content.hs
|
@ -57,11 +57,11 @@ calcGitLink :: FilePath -> Key -> Annex FilePath
|
||||||
calcGitLink file key = do
|
calcGitLink file key = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
cwd <- liftIO $ getCurrentDirectory
|
cwd <- liftIO $ getCurrentDirectory
|
||||||
let absfile = case absNormPath cwd file of
|
let absfile = maybe whoops id $ absNormPath cwd file
|
||||||
Just f -> f
|
|
||||||
Nothing -> error $ "unable to normalize " ++ file
|
|
||||||
return $ relPathDirToFile (parentDir absfile)
|
return $ relPathDirToFile (parentDir absfile)
|
||||||
(Git.workTree g) </> ".git" </> annexLocation key
|
(Git.workTree g) </> ".git" </> annexLocation key
|
||||||
|
where
|
||||||
|
whoops = error $ "unable to normalize " ++ file
|
||||||
|
|
||||||
{- Updates the LocationLog when a key's presence changes in the current
|
{- Updates the LocationLog when a key's presence changes in the current
|
||||||
- repository.
|
- repository.
|
||||||
|
@ -148,9 +148,7 @@ checkDiskSpace' :: Integer -> Key -> Annex ()
|
||||||
checkDiskSpace' adjustment key = do
|
checkDiskSpace' adjustment key = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
r <- getConfig g "diskreserve" ""
|
r <- getConfig g "diskreserve" ""
|
||||||
let reserve = case readSize dataUnits r of
|
let reserve = maybe megabyte id $ readSize dataUnits r
|
||||||
Nothing -> megabyte
|
|
||||||
Just v -> v
|
|
||||||
stats <- liftIO $ getFileSystemStats (gitAnnexDir g)
|
stats <- liftIO $ getFileSystemStats (gitAnnexDir g)
|
||||||
case (stats, keySize key) of
|
case (stats, keySize key) of
|
||||||
(Nothing, _) -> return ()
|
(Nothing, _) -> return ()
|
||||||
|
|
|
@ -238,10 +238,8 @@ configKeyIds c = do
|
||||||
keyIdField s = (split ":" s) !! 4
|
keyIdField s = (split ":" s) !! 4
|
||||||
|
|
||||||
configGet :: RemoteConfig -> String -> String
|
configGet :: RemoteConfig -> String -> String
|
||||||
configGet c key =
|
configGet c key = maybe missing id $ M.lookup key c
|
||||||
case M.lookup key c of
|
where missing = error $ "missing " ++ key ++ " in remote config"
|
||||||
Just v -> v
|
|
||||||
Nothing -> error $ "missing " ++ key ++ " in remote config"
|
|
||||||
|
|
||||||
hmacWithCipher :: Cipher -> String -> String
|
hmacWithCipher :: Cipher -> String -> String
|
||||||
hmacWithCipher c = hmacWithCipher' (cipherHmac c)
|
hmacWithCipher c = hmacWithCipher' (cipherHmac c)
|
||||||
|
|
5
Dot.hs
5
Dot.hs
|
@ -20,10 +20,7 @@ graphNode nodeid desc = label desc $ quote nodeid
|
||||||
|
|
||||||
{- an edge between two nodes -}
|
{- an edge between two nodes -}
|
||||||
graphEdge :: String -> String -> Maybe String -> String
|
graphEdge :: String -> String -> Maybe String -> String
|
||||||
graphEdge fromid toid desc = indent $
|
graphEdge fromid toid desc = indent $ maybe edge (\d -> label d edge) desc
|
||||||
case desc of
|
|
||||||
Nothing -> edge
|
|
||||||
Just d -> label d edge
|
|
||||||
where
|
where
|
||||||
edge = quote fromid ++ " -> " ++ quote toid
|
edge = quote fromid ++ " -> " ++ quote toid
|
||||||
|
|
||||||
|
|
13
GitRepo.hs
13
GitRepo.hs
|
@ -122,9 +122,8 @@ repoFromUrl url
|
||||||
| startswith "file://" url = repoFromAbsPath $ uriPath u
|
| startswith "file://" url = repoFromAbsPath $ uriPath u
|
||||||
| otherwise = return $ newFrom $ Url u
|
| otherwise = return $ newFrom $ Url u
|
||||||
where
|
where
|
||||||
u = case (parseURI url) of
|
u = maybe bad id $ parseURI url
|
||||||
Just v -> v
|
bad = error $ "bad url " ++ url
|
||||||
Nothing -> error $ "bad url " ++ url
|
|
||||||
|
|
||||||
{- Creates a repo that has an unknown location. -}
|
{- Creates a repo that has an unknown location. -}
|
||||||
repoFromUnknown :: Repo
|
repoFromUnknown :: Repo
|
||||||
|
@ -264,9 +263,7 @@ workTreeFile repo@(Repo { location = Dir d }) file = do
|
||||||
absrepo = case (absNormPath "/" d) of
|
absrepo = case (absNormPath "/" d) of
|
||||||
Just f -> addTrailingPathSeparator f
|
Just f -> addTrailingPathSeparator f
|
||||||
Nothing -> error $ "bad repo" ++ repoDescribe repo
|
Nothing -> error $ "bad repo" ++ repoDescribe repo
|
||||||
absfile c = case (secureAbsNormPath c file) of
|
absfile c = maybe file id $ secureAbsNormPath c file
|
||||||
Just f -> f
|
|
||||||
Nothing -> file
|
|
||||||
inrepo f = absrepo `isPrefixOf` f
|
inrepo f = absrepo `isPrefixOf` f
|
||||||
workTreeFile repo _ = assertLocal repo $ error "internal"
|
workTreeFile repo _ = assertLocal repo $ error "internal"
|
||||||
|
|
||||||
|
@ -352,9 +349,7 @@ reap :: IO ()
|
||||||
reap = do
|
reap = do
|
||||||
-- throws an exception when there are no child processes
|
-- throws an exception when there are no child processes
|
||||||
r <- catch (getAnyProcessStatus False True) (\_ -> return Nothing)
|
r <- catch (getAnyProcessStatus False True) (\_ -> return Nothing)
|
||||||
case r of
|
maybe (return ()) (const reap) r
|
||||||
Nothing -> return ()
|
|
||||||
Just _ -> reap
|
|
||||||
|
|
||||||
{- Scans for files that are checked into git at the specified locations. -}
|
{- Scans for files that are checked into git at the specified locations. -}
|
||||||
inRepo :: Repo -> [FilePath] -> IO [FilePath]
|
inRepo :: Repo -> [FilePath] -> IO [FilePath]
|
||||||
|
|
|
@ -71,9 +71,7 @@ instance Read LogLine where
|
||||||
-- Such lines have a status of Undefined.
|
-- Such lines have a status of Undefined.
|
||||||
readsPrec _ string =
|
readsPrec _ string =
|
||||||
if length w == 3
|
if length w == 3
|
||||||
then case pdate of
|
then maybe bad good pdate
|
||||||
Just v -> good v
|
|
||||||
Nothing -> bad
|
|
||||||
else bad
|
else bad
|
||||||
where
|
where
|
||||||
w = words string
|
w = words string
|
||||||
|
|
|
@ -68,9 +68,8 @@ gen r u c = do
|
||||||
bupSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
bupSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||||
bupSetup u c = do
|
bupSetup u c = do
|
||||||
-- verify configuration is sane
|
-- verify configuration is sane
|
||||||
let buprepo = case M.lookup "buprepo" c of
|
let buprepo = maybe (error "Specify buprepo=") id $
|
||||||
Nothing -> error "Specify buprepo="
|
M.lookup "buprepo" c
|
||||||
Just r -> r
|
|
||||||
c' <- encryptionSetup c
|
c' <- encryptionSetup c
|
||||||
|
|
||||||
-- bup init will create the repository.
|
-- bup init will create the repository.
|
||||||
|
|
|
@ -60,9 +60,8 @@ gen r u c = do
|
||||||
directorySetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
directorySetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||||
directorySetup u c = do
|
directorySetup u c = do
|
||||||
-- verify configuration is sane
|
-- verify configuration is sane
|
||||||
let dir = case M.lookup "directory" c of
|
let dir = maybe (error "Specify directory=") id $
|
||||||
Nothing -> error "Specify directory="
|
M.lookup "directory" c
|
||||||
Just d -> d
|
|
||||||
e <- liftIO $ doesDirectoryExist dir
|
e <- liftIO $ doesDirectoryExist dir
|
||||||
when (not e) $ error $ "Directory does not exist: " ++ dir
|
when (not e) $ error $ "Directory does not exist: " ++ dir
|
||||||
c' <- encryptionSetup c
|
c' <- encryptionSetup c
|
||||||
|
|
|
@ -73,11 +73,10 @@ encryptableRemote c storeKeyEncrypted retrieveKeyFileEncrypted r =
|
||||||
{- Gets encryption Cipher. The decrypted Cipher is cached in the Annex
|
{- Gets encryption Cipher. The decrypted Cipher is cached in the Annex
|
||||||
- state. -}
|
- state. -}
|
||||||
remoteCipher :: RemoteConfig -> Annex (Maybe Cipher)
|
remoteCipher :: RemoteConfig -> Annex (Maybe Cipher)
|
||||||
remoteCipher c = do
|
remoteCipher c = maybe expensive cached =<< Annex.getState Annex.cipher
|
||||||
cache <- Annex.getState Annex.cipher
|
where
|
||||||
case cache of
|
cached cipher = return $ Just cipher
|
||||||
Just cipher -> return $ Just cipher
|
expensive = case extractCipher c of
|
||||||
Nothing -> case extractCipher c of
|
|
||||||
Nothing -> return Nothing
|
Nothing -> return Nothing
|
||||||
Just encipher -> do
|
Just encipher -> do
|
||||||
showNote "gpg"
|
showNote "gpg"
|
||||||
|
|
|
@ -61,9 +61,8 @@ gen r u c = do
|
||||||
|
|
||||||
hookSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
hookSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||||
hookSetup u c = do
|
hookSetup u c = do
|
||||||
let hooktype = case M.lookup "hooktype" c of
|
let hooktype = maybe (error "Specify hooktype=") id $
|
||||||
Nothing -> error "Specify hooktype="
|
M.lookup "hooktype" c
|
||||||
Just r -> r
|
|
||||||
c' <- encryptionSetup c
|
c' <- encryptionSetup c
|
||||||
gitConfigSpecialRemote u c' "hooktype" hooktype
|
gitConfigSpecialRemote u c' "hooktype" hooktype
|
||||||
return c'
|
return c'
|
||||||
|
@ -94,14 +93,12 @@ lookupHook hooktype hook =do
|
||||||
hookname = hooktype ++ "-" ++ hook ++ "-hook"
|
hookname = hooktype ++ "-" ++ hook ++ "-hook"
|
||||||
|
|
||||||
runHook :: String -> String -> Key -> Maybe FilePath -> Annex Bool -> Annex Bool
|
runHook :: String -> String -> Key -> Maybe FilePath -> Annex Bool -> Annex Bool
|
||||||
runHook hooktype hook k f a = do
|
runHook hooktype hook k f a = maybe (return False) run =<< lookupHook hooktype hook
|
||||||
command <- lookupHook hooktype hook
|
where
|
||||||
case command of
|
run command = do
|
||||||
Nothing -> return False
|
|
||||||
Just c -> do
|
|
||||||
showProgress -- make way for hook output
|
showProgress -- make way for hook output
|
||||||
res <- liftIO $ boolSystemEnv
|
res <- liftIO $ boolSystemEnv
|
||||||
"sh" [Param "-c", Param c] $ hookEnv k f
|
"sh" [Param "-c", Param command] $ hookEnv k f
|
||||||
if res
|
if res
|
||||||
then a
|
then a
|
||||||
else do
|
else do
|
||||||
|
|
|
@ -82,9 +82,8 @@ genRsyncOpts r = do
|
||||||
rsyncSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
rsyncSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||||
rsyncSetup u c = do
|
rsyncSetup u c = do
|
||||||
-- verify configuration is sane
|
-- verify configuration is sane
|
||||||
let url = case M.lookup "rsyncurl" c of
|
let url = maybe (error "Specify rsyncurl=") id $
|
||||||
Nothing -> error "Specify rsyncurl="
|
M.lookup "rsyncurl" c
|
||||||
Just d -> d
|
|
||||||
c' <- encryptionSetup c
|
c' <- encryptionSetup c
|
||||||
|
|
||||||
-- The rsyncurl is stored in git config, not only in this remote's
|
-- 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
|
content <- liftIO $ L.readFile file
|
||||||
-- size is provided to S3 so the whole content does not need to be
|
-- size is provided to S3 so the whole content does not need to be
|
||||||
-- buffered to calculate it
|
-- buffered to calculate it
|
||||||
size <- case keySize k of
|
size <- maybe getsize (return . fromIntegral) $ keySize k
|
||||||
Just s -> return $ fromIntegral s
|
|
||||||
Nothing -> do
|
|
||||||
s <- liftIO $ getFileStatus file
|
|
||||||
return $ fileSize s
|
|
||||||
let object = setStorageClass storageclass $
|
let object = setStorageClass storageclass $
|
||||||
S3Object bucket (show k) ""
|
S3Object bucket (show k) ""
|
||||||
[("Content-Length",(show size))] content
|
[("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
|
case fromJust $ M.lookup "storageclass" $ fromJust $ config r of
|
||||||
"REDUCED_REDUNDANCY" -> REDUCED_REDUNDANCY
|
"REDUCED_REDUNDANCY" -> REDUCED_REDUNDANCY
|
||||||
_ -> STANDARD
|
_ -> STANDARD
|
||||||
|
getsize = do
|
||||||
|
s <- liftIO $ getFileStatus file
|
||||||
|
return $ fileSize s
|
||||||
|
|
||||||
retrieve :: Remote Annex -> Key -> FilePath -> Annex Bool
|
retrieve :: Remote Annex -> Key -> FilePath -> Annex Bool
|
||||||
retrieve r k f = s3Action r False $ \(conn, bucket) -> do
|
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
|
bucketKey bucket k = S3Object bucket (show k) "" [] L.empty
|
||||||
|
|
||||||
s3ConnectionRequired :: RemoteConfig -> Annex AWSConnection
|
s3ConnectionRequired :: RemoteConfig -> Annex AWSConnection
|
||||||
s3ConnectionRequired c = do
|
s3ConnectionRequired c =
|
||||||
conn <- s3Connection c
|
maybe (error "Cannot connect to S3") return =<< s3Connection c
|
||||||
case conn of
|
|
||||||
Nothing -> error "Cannot connect to S3"
|
|
||||||
Just conn' -> return conn'
|
|
||||||
|
|
||||||
s3Connection :: RemoteConfig -> Annex (Maybe AWSConnection)
|
s3Connection :: RemoteConfig -> Annex (Maybe AWSConnection)
|
||||||
s3Connection c = do
|
s3Connection c = do
|
||||||
|
|
11
Utility.hs
11
Utility.hs
|
@ -165,9 +165,7 @@ prop_parentDir_basics dir
|
||||||
dirContains :: FilePath -> FilePath -> Bool
|
dirContains :: FilePath -> FilePath -> Bool
|
||||||
dirContains a b = a == b || a' == b' || (a'++"/") `isPrefixOf` b'
|
dirContains a b = a == b || a' == b' || (a'++"/") `isPrefixOf` b'
|
||||||
where
|
where
|
||||||
norm p = case (absNormPath p ".") of
|
norm p = maybe "" id $ absNormPath p "."
|
||||||
Just r -> r
|
|
||||||
Nothing -> ""
|
|
||||||
a' = norm a
|
a' = norm a
|
||||||
b' = norm b
|
b' = norm b
|
||||||
|
|
||||||
|
@ -180,10 +178,9 @@ absPath file = do
|
||||||
{- Converts a filename into a normalized, absolute path
|
{- Converts a filename into a normalized, absolute path
|
||||||
- from the specified cwd. -}
|
- from the specified cwd. -}
|
||||||
absPathFrom :: FilePath -> FilePath -> FilePath
|
absPathFrom :: FilePath -> FilePath -> FilePath
|
||||||
absPathFrom cwd file =
|
absPathFrom cwd file = maybe bad id $ absNormPath cwd file
|
||||||
case absNormPath cwd file of
|
where
|
||||||
Just f -> f
|
bad = error $ "unable to normalize " ++ file
|
||||||
Nothing -> error $ "unable to normalize " ++ file
|
|
||||||
|
|
||||||
{- Constructs a relative path from the CWD to a file.
|
{- Constructs a relative path from the CWD to a file.
|
||||||
-
|
-
|
||||||
|
|
Loading…
Add table
Reference in a new issue