avoid unnecessary Maybe
This commit is contained in:
parent
d56a5c9996
commit
020a25abe1
13 changed files with 112 additions and 128 deletions
|
@ -38,7 +38,7 @@ remote = RemoteType {
|
||||||
setup = bupSetup
|
setup = bupSetup
|
||||||
}
|
}
|
||||||
|
|
||||||
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex Remote
|
gen :: Git.Repo -> UUID -> RemoteConfig -> Annex Remote
|
||||||
gen r u c = do
|
gen r u c = do
|
||||||
buprepo <- getRemoteConfig r "buprepo" (error "missing buprepo")
|
buprepo <- getRemoteConfig r "buprepo" (error "missing buprepo")
|
||||||
cst <- remoteCost r (if bupLocal buprepo then semiCheapRemoteCost else expensiveRemoteCost)
|
cst <- remoteCost r (if bupLocal buprepo then semiCheapRemoteCost else expensiveRemoteCost)
|
||||||
|
|
|
@ -33,7 +33,7 @@ remote = RemoteType {
|
||||||
setup = directorySetup
|
setup = directorySetup
|
||||||
}
|
}
|
||||||
|
|
||||||
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex Remote
|
gen :: Git.Repo -> UUID -> RemoteConfig -> Annex Remote
|
||||||
gen r u c = do
|
gen r u c = do
|
||||||
dir <- getRemoteConfig r "directory" (error "missing directory")
|
dir <- getRemoteConfig r "directory" (error "missing directory")
|
||||||
cst <- remoteCost r cheapRemoteCost
|
cst <- remoteCost r cheapRemoteCost
|
||||||
|
@ -52,7 +52,7 @@ gen r u c = do
|
||||||
hasKey = checkPresent dir chunksize,
|
hasKey = checkPresent dir chunksize,
|
||||||
hasKeyCheap = True,
|
hasKeyCheap = True,
|
||||||
whereisKey = Nothing,
|
whereisKey = Nothing,
|
||||||
config = Nothing,
|
config = M.empty,
|
||||||
repo = r,
|
repo = r,
|
||||||
localpath = Just dir,
|
localpath = Just dir,
|
||||||
readonly = False,
|
readonly = False,
|
||||||
|
|
|
@ -83,7 +83,7 @@ configRead r = do
|
||||||
repoCheap :: Git.Repo -> Bool
|
repoCheap :: Git.Repo -> Bool
|
||||||
repoCheap = not . Git.repoIsUrl
|
repoCheap = not . Git.repoIsUrl
|
||||||
|
|
||||||
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex Remote
|
gen :: Git.Repo -> UUID -> RemoteConfig -> Annex Remote
|
||||||
gen r u _ = new <$> remoteCost r defcst
|
gen r u _ = new <$> remoteCost r defcst
|
||||||
where
|
where
|
||||||
defcst = if repoCheap r then cheapRemoteCost else expensiveRemoteCost
|
defcst = if repoCheap r then cheapRemoteCost else expensiveRemoteCost
|
||||||
|
@ -98,7 +98,7 @@ gen r u _ = new <$> remoteCost r defcst
|
||||||
, hasKey = inAnnex r
|
, hasKey = inAnnex r
|
||||||
, hasKeyCheap = repoCheap r
|
, hasKeyCheap = repoCheap r
|
||||||
, whereisKey = Nothing
|
, whereisKey = Nothing
|
||||||
, config = Nothing
|
, config = M.empty
|
||||||
, localpath = if Git.repoIsLocal r || Git.repoIsLocalUnknown r
|
, localpath = if Git.repoIsLocal r || Git.repoIsLocalUnknown r
|
||||||
then Just $ Git.repoPath r
|
then Just $ Git.repoPath r
|
||||||
else Nothing
|
else Nothing
|
||||||
|
|
|
@ -36,34 +36,31 @@ remote = RemoteType {
|
||||||
setup = glacierSetup
|
setup = glacierSetup
|
||||||
}
|
}
|
||||||
|
|
||||||
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex Remote
|
gen :: Git.Repo -> UUID -> RemoteConfig -> Annex Remote
|
||||||
gen r u c = do
|
gen r u c = new <$> remoteCost r veryExpensiveRemoteCost
|
||||||
cst <- remoteCost r veryExpensiveRemoteCost
|
where
|
||||||
return $ gen' r u c cst
|
new cst = encryptableRemote c
|
||||||
gen' :: Git.Repo -> UUID -> Maybe RemoteConfig -> Int -> Remote
|
|
||||||
gen' r u c cst =
|
|
||||||
encryptableRemote c
|
|
||||||
(storeEncrypted this)
|
(storeEncrypted this)
|
||||||
(retrieveEncrypted this)
|
(retrieveEncrypted this)
|
||||||
this
|
this
|
||||||
where
|
where
|
||||||
this = Remote {
|
this = Remote {
|
||||||
uuid = u,
|
uuid = u,
|
||||||
cost = cst,
|
cost = cst,
|
||||||
name = Git.repoDescribe r,
|
name = Git.repoDescribe r,
|
||||||
storeKey = store this,
|
storeKey = store this,
|
||||||
retrieveKeyFile = retrieve this,
|
retrieveKeyFile = retrieve this,
|
||||||
retrieveKeyFileCheap = retrieveCheap this,
|
retrieveKeyFileCheap = retrieveCheap this,
|
||||||
removeKey = remove this,
|
removeKey = remove this,
|
||||||
hasKey = checkPresent this,
|
hasKey = checkPresent this,
|
||||||
hasKeyCheap = False,
|
hasKeyCheap = False,
|
||||||
whereisKey = Nothing,
|
whereisKey = Nothing,
|
||||||
config = c,
|
config = c,
|
||||||
repo = r,
|
repo = r,
|
||||||
localpath = Nothing,
|
localpath = Nothing,
|
||||||
readonly = False,
|
readonly = False,
|
||||||
remotetype = remote
|
remotetype = remote
|
||||||
}
|
}
|
||||||
|
|
||||||
glacierSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
glacierSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||||
glacierSetup u c = do
|
glacierSetup u c = do
|
||||||
|
@ -115,13 +112,13 @@ retrieveEncrypted r (cipher, enck) k d = metered Nothing k $ \meterupdate ->
|
||||||
storeHelper :: Remote -> Key -> (Handle -> IO ()) -> Annex Bool
|
storeHelper :: Remote -> Key -> (Handle -> IO ()) -> Annex Bool
|
||||||
storeHelper r k feeder = go =<< glacierEnv c u
|
storeHelper r k feeder = go =<< glacierEnv c u
|
||||||
where
|
where
|
||||||
c = fromJust $ config r
|
c = config r
|
||||||
u = uuid r
|
u = uuid r
|
||||||
params = glacierParams c
|
params = glacierParams c
|
||||||
[ Param "archive"
|
[ Param "archive"
|
||||||
, Param "upload"
|
, Param "upload"
|
||||||
, Param "--name", Param $ archive r k
|
, Param "--name", Param $ archive r k
|
||||||
, Param $ remoteVault r
|
, Param $ getVault $ config r
|
||||||
, Param "-"
|
, Param "-"
|
||||||
]
|
]
|
||||||
go Nothing = return False
|
go Nothing = return False
|
||||||
|
@ -135,13 +132,13 @@ storeHelper r k feeder = go =<< glacierEnv c u
|
||||||
retrieveHelper :: Remote -> Key -> (Handle -> IO ()) -> Annex Bool
|
retrieveHelper :: Remote -> Key -> (Handle -> IO ()) -> Annex Bool
|
||||||
retrieveHelper r k reader = go =<< glacierEnv c u
|
retrieveHelper r k reader = go =<< glacierEnv c u
|
||||||
where
|
where
|
||||||
c = fromJust $ config r
|
c = config r
|
||||||
u = uuid r
|
u = uuid r
|
||||||
params = glacierParams c
|
params = glacierParams c
|
||||||
[ Param "archive"
|
[ Param "archive"
|
||||||
, Param "retrieve"
|
, Param "retrieve"
|
||||||
, Param "-o-"
|
, Param "-o-"
|
||||||
, Param $ remoteVault r
|
, Param $ getVault $ config r
|
||||||
, Param $ archive r k
|
, Param $ archive r k
|
||||||
]
|
]
|
||||||
go Nothing = return False
|
go Nothing = return False
|
||||||
|
@ -163,14 +160,14 @@ remove :: Remote -> Key -> Annex Bool
|
||||||
remove r k = glacierAction r
|
remove r k = glacierAction r
|
||||||
[ Param "archive"
|
[ Param "archive"
|
||||||
, Param "delete"
|
, Param "delete"
|
||||||
, Param $ remoteVault r
|
, Param $ getVault $ config r
|
||||||
, Param $ archive r k
|
, Param $ archive r k
|
||||||
]
|
]
|
||||||
|
|
||||||
checkPresent :: Remote -> Key -> Annex (Either String Bool)
|
checkPresent :: Remote -> Key -> Annex (Either String Bool)
|
||||||
checkPresent r k = do
|
checkPresent r k = do
|
||||||
showAction $ "checking " ++ name r
|
showAction $ "checking " ++ name r
|
||||||
go =<< glacierEnv (fromJust $ config r) (uuid r)
|
go =<< glacierEnv (config r) (uuid r)
|
||||||
where
|
where
|
||||||
go Nothing = return $ Left "cannot check glacier"
|
go Nothing = return $ Left "cannot check glacier"
|
||||||
go (Just e) = do
|
go (Just e) = do
|
||||||
|
@ -190,7 +187,7 @@ checkPresent r k = do
|
||||||
params =
|
params =
|
||||||
[ Param "archive"
|
[ Param "archive"
|
||||||
, Param "checkpresent"
|
, Param "checkpresent"
|
||||||
, Param $ remoteVault r
|
, Param $ getVault $ config r
|
||||||
, Param "--quiet"
|
, Param "--quiet"
|
||||||
, Param $ archive r k
|
, Param $ archive r k
|
||||||
]
|
]
|
||||||
|
@ -205,7 +202,7 @@ checkPresent r k = do
|
||||||
return $ Right False
|
return $ Right False
|
||||||
|
|
||||||
glacierAction :: Remote -> [CommandParam] -> Annex Bool
|
glacierAction :: Remote -> [CommandParam] -> Annex Bool
|
||||||
glacierAction r params = runGlacier (fromJust $ config r) (uuid r) params
|
glacierAction r params = runGlacier (config r) (uuid r) params
|
||||||
|
|
||||||
runGlacier :: RemoteConfig -> UUID -> [CommandParam] -> Annex Bool
|
runGlacier :: RemoteConfig -> UUID -> [CommandParam] -> Annex Bool
|
||||||
runGlacier c u params = go =<< glacierEnv c u
|
runGlacier c u params = go =<< glacierEnv c u
|
||||||
|
@ -231,16 +228,13 @@ glacierEnv c u = go =<< getRemoteCredPairFor "glacier" c creds
|
||||||
creds = AWS.creds u
|
creds = AWS.creds u
|
||||||
(uk, pk) = credPairEnvironment creds
|
(uk, pk) = credPairEnvironment creds
|
||||||
|
|
||||||
remoteVault :: Remote -> Vault
|
|
||||||
remoteVault = getVault . fromJust . config
|
|
||||||
|
|
||||||
getVault :: RemoteConfig -> Vault
|
getVault :: RemoteConfig -> Vault
|
||||||
getVault = fromJust . M.lookup "vault"
|
getVault = fromJust . M.lookup "vault"
|
||||||
|
|
||||||
archive :: Remote -> Key -> Archive
|
archive :: Remote -> Key -> Archive
|
||||||
archive r k = fileprefix ++ key2file k
|
archive r k = fileprefix ++ key2file k
|
||||||
where
|
where
|
||||||
fileprefix = M.findWithDefault "" "fileprefix" $ fromJust $ config r
|
fileprefix = M.findWithDefault "" "fileprefix" $ config r
|
||||||
|
|
||||||
-- glacier vault create will succeed even if the vault already exists.
|
-- glacier vault create will succeed even if the vault already exists.
|
||||||
genVault :: RemoteConfig -> UUID -> Annex ()
|
genVault :: RemoteConfig -> UUID -> Annex ()
|
||||||
|
@ -260,11 +254,11 @@ genVault c u = unlessM (runGlacier c u params) $
|
||||||
- keys when the remote is encrypted.
|
- keys when the remote is encrypted.
|
||||||
-}
|
-}
|
||||||
jobList :: Remote -> [Key] -> Annex ([Key], [Key])
|
jobList :: Remote -> [Key] -> Annex ([Key], [Key])
|
||||||
jobList r keys = go =<< glacierEnv (fromJust $ config r) (uuid r)
|
jobList r keys = go =<< glacierEnv (config r) (uuid r)
|
||||||
where
|
where
|
||||||
params = [ Param "job", Param "list" ]
|
params = [ Param "job", Param "list" ]
|
||||||
nada = ([], [])
|
nada = ([], [])
|
||||||
myvault = remoteVault r
|
myvault = getVault $ config r
|
||||||
|
|
||||||
go Nothing = return nada
|
go Nothing = return nada
|
||||||
go (Just e) = do
|
go (Just e) = do
|
||||||
|
|
|
@ -20,9 +20,8 @@ import qualified Control.Exception as E
|
||||||
type ChunkSize = Maybe Int64
|
type ChunkSize = Maybe Int64
|
||||||
|
|
||||||
{- Gets a remote's configured chunk size. -}
|
{- Gets a remote's configured chunk size. -}
|
||||||
chunkSize :: Maybe RemoteConfig -> ChunkSize
|
chunkSize :: RemoteConfig -> ChunkSize
|
||||||
chunkSize Nothing = Nothing
|
chunkSize m =
|
||||||
chunkSize (Just m) =
|
|
||||||
case M.lookup "chunksize" m of
|
case M.lookup "chunksize" m of
|
||||||
Nothing -> Nothing
|
Nothing -> Nothing
|
||||||
Just v -> case readSize dataUnits v of
|
Just v -> case readSize dataUnits v of
|
||||||
|
|
|
@ -44,7 +44,7 @@ encryptionSetup c = case (M.lookup "encryption" c, extractCipher c) of
|
||||||
- Two additional functions must be provided by the remote,
|
- Two additional functions must be provided by the remote,
|
||||||
- to support storing and retrieving encrypted content. -}
|
- to support storing and retrieving encrypted content. -}
|
||||||
encryptableRemote
|
encryptableRemote
|
||||||
:: Maybe RemoteConfig
|
:: RemoteConfig
|
||||||
-> ((Cipher, Key) -> Key -> MeterUpdate -> Annex Bool)
|
-> ((Cipher, Key) -> Key -> MeterUpdate -> Annex Bool)
|
||||||
-> ((Cipher, Key) -> Key -> FilePath -> Annex Bool)
|
-> ((Cipher, Key) -> Key -> FilePath -> Annex Bool)
|
||||||
-> Remote
|
-> Remote
|
||||||
|
@ -103,9 +103,8 @@ embedCreds c
|
||||||
| otherwise = False
|
| otherwise = False
|
||||||
|
|
||||||
{- Gets encryption Cipher, and encrypted version of Key. -}
|
{- Gets encryption Cipher, and encrypted version of Key. -}
|
||||||
cipherKey :: Maybe RemoteConfig -> Key -> Annex (Maybe (Cipher, Key))
|
cipherKey :: RemoteConfig -> Key -> Annex (Maybe (Cipher, Key))
|
||||||
cipherKey Nothing _ = return Nothing
|
cipherKey c k = maybe Nothing make <$> remoteCipher c
|
||||||
cipherKey (Just c) k = maybe Nothing make <$> remoteCipher c
|
|
||||||
where
|
where
|
||||||
make ciphertext = Just (ciphertext, encryptKey ciphertext k)
|
make ciphertext = Just (ciphertext, encryptKey ciphertext k)
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ remote = RemoteType {
|
||||||
setup = hookSetup
|
setup = hookSetup
|
||||||
}
|
}
|
||||||
|
|
||||||
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex Remote
|
gen :: Git.Repo -> UUID -> RemoteConfig -> Annex Remote
|
||||||
gen r u c = do
|
gen r u c = do
|
||||||
hooktype <- getRemoteConfig r "hooktype" (error "missing hooktype")
|
hooktype <- getRemoteConfig r "hooktype" (error "missing hooktype")
|
||||||
cst <- remoteCost r expensiveRemoteCost
|
cst <- remoteCost r expensiveRemoteCost
|
||||||
|
@ -47,7 +47,7 @@ gen r u c = do
|
||||||
hasKey = checkPresent r hooktype,
|
hasKey = checkPresent r hooktype,
|
||||||
hasKeyCheap = False,
|
hasKeyCheap = False,
|
||||||
whereisKey = Nothing,
|
whereisKey = Nothing,
|
||||||
config = Nothing,
|
config = M.empty,
|
||||||
localpath = Nothing,
|
localpath = Nothing,
|
||||||
repo = r,
|
repo = r,
|
||||||
readonly = False,
|
readonly = False,
|
||||||
|
|
|
@ -81,7 +81,7 @@ remoteListRefresh = do
|
||||||
remoteGen :: (M.Map UUID RemoteConfig) -> RemoteType -> Git.Repo -> Annex Remote
|
remoteGen :: (M.Map UUID RemoteConfig) -> RemoteType -> Git.Repo -> Annex Remote
|
||||||
remoteGen m t r = do
|
remoteGen m t r = do
|
||||||
u <- getRepoUUID r
|
u <- getRepoUUID r
|
||||||
addHooks =<< generate t r u (M.lookup u m)
|
addHooks =<< generate t r u (fromMaybe M.empty $ M.lookup u m)
|
||||||
|
|
||||||
{- Updates a local git Remote, re-reading its git config. -}
|
{- Updates a local git Remote, re-reading its git config. -}
|
||||||
updateRemote :: Remote -> Annex Remote
|
updateRemote :: Remote -> Annex Remote
|
||||||
|
|
|
@ -38,7 +38,7 @@ remote = RemoteType {
|
||||||
setup = rsyncSetup
|
setup = rsyncSetup
|
||||||
}
|
}
|
||||||
|
|
||||||
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex Remote
|
gen :: Git.Repo -> UUID -> RemoteConfig -> Annex Remote
|
||||||
gen r u c = do
|
gen r u c = do
|
||||||
o <- genRsyncOpts r c
|
o <- genRsyncOpts r c
|
||||||
cst <- remoteCost r expensiveRemoteCost
|
cst <- remoteCost r expensiveRemoteCost
|
||||||
|
@ -56,7 +56,7 @@ gen r u c = do
|
||||||
, hasKey = checkPresent r o
|
, hasKey = checkPresent r o
|
||||||
, hasKeyCheap = False
|
, hasKeyCheap = False
|
||||||
, whereisKey = Nothing
|
, whereisKey = Nothing
|
||||||
, config = Nothing
|
, config = M.empty
|
||||||
, repo = r
|
, repo = r
|
||||||
, localpath = if rsyncUrlIsPath $ rsyncUrl o
|
, localpath = if rsyncUrlIsPath $ rsyncUrl o
|
||||||
then Just $ rsyncUrl o
|
then Just $ rsyncUrl o
|
||||||
|
@ -65,12 +65,12 @@ gen r u c = do
|
||||||
, remotetype = remote
|
, remotetype = remote
|
||||||
}
|
}
|
||||||
|
|
||||||
genRsyncOpts :: Git.Repo -> Maybe RemoteConfig -> Annex RsyncOpts
|
genRsyncOpts :: Git.Repo -> RemoteConfig -> Annex RsyncOpts
|
||||||
genRsyncOpts r c = do
|
genRsyncOpts r c = do
|
||||||
url <- getRemoteConfig r "rsyncurl" (error "missing rsyncurl")
|
url <- getRemoteConfig r "rsyncurl" (error "missing rsyncurl")
|
||||||
opts <- map Param . filter safe . words
|
opts <- map Param . filter safe . words
|
||||||
<$> getRemoteConfig r "rsync-options" ""
|
<$> getRemoteConfig r "rsync-options" ""
|
||||||
let escape = maybe True (\m -> M.lookup "shellescape" m /= Just "no") c
|
let escape = M.lookup "shellescape" c /= Just "no"
|
||||||
return $ RsyncOpts url opts escape
|
return $ RsyncOpts url opts escape
|
||||||
where
|
where
|
||||||
safe o
|
safe o
|
||||||
|
|
59
Remote/S3.hs
59
Remote/S3.hs
|
@ -36,34 +36,31 @@ remote = RemoteType {
|
||||||
setup = s3Setup
|
setup = s3Setup
|
||||||
}
|
}
|
||||||
|
|
||||||
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex Remote
|
gen :: Git.Repo -> UUID -> RemoteConfig -> Annex Remote
|
||||||
gen r u c = do
|
gen r u c = new <$> remoteCost r expensiveRemoteCost
|
||||||
cst <- remoteCost r expensiveRemoteCost
|
where
|
||||||
return $ gen' r u c cst
|
new cst = encryptableRemote c
|
||||||
gen' :: Git.Repo -> UUID -> Maybe RemoteConfig -> Int -> Remote
|
|
||||||
gen' r u c cst =
|
|
||||||
encryptableRemote c
|
|
||||||
(storeEncrypted this)
|
(storeEncrypted this)
|
||||||
(retrieveEncrypted this)
|
(retrieveEncrypted this)
|
||||||
this
|
this
|
||||||
where
|
where
|
||||||
this = Remote {
|
this = Remote {
|
||||||
uuid = u,
|
uuid = u,
|
||||||
cost = cst,
|
cost = cst,
|
||||||
name = Git.repoDescribe r,
|
name = Git.repoDescribe r,
|
||||||
storeKey = store this,
|
storeKey = store this,
|
||||||
retrieveKeyFile = retrieve this,
|
retrieveKeyFile = retrieve this,
|
||||||
retrieveKeyFileCheap = retrieveCheap this,
|
retrieveKeyFileCheap = retrieveCheap this,
|
||||||
removeKey = remove this,
|
removeKey = remove this,
|
||||||
hasKey = checkPresent this,
|
hasKey = checkPresent this,
|
||||||
hasKeyCheap = False,
|
hasKeyCheap = False,
|
||||||
whereisKey = Nothing,
|
whereisKey = Nothing,
|
||||||
config = c,
|
config = c,
|
||||||
repo = r,
|
repo = r,
|
||||||
localpath = Nothing,
|
localpath = Nothing,
|
||||||
readonly = False,
|
readonly = False,
|
||||||
remotetype = remote
|
remotetype = remote
|
||||||
}
|
}
|
||||||
|
|
||||||
s3Setup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
s3Setup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||||
s3Setup u c = handlehost $ M.lookup "host" c
|
s3Setup u c = handlehost $ M.lookup "host" c
|
||||||
|
@ -143,13 +140,13 @@ storeHelper (conn, bucket) r k p file = do
|
||||||
sendObject conn object
|
sendObject conn object
|
||||||
where
|
where
|
||||||
storageclass =
|
storageclass =
|
||||||
case fromJust $ M.lookup "storageclass" $ fromJust $ config r of
|
case fromJust $ M.lookup "storageclass" $ config r of
|
||||||
"REDUCED_REDUNDANCY" -> REDUCED_REDUNDANCY
|
"REDUCED_REDUNDANCY" -> REDUCED_REDUNDANCY
|
||||||
_ -> STANDARD
|
_ -> STANDARD
|
||||||
|
|
||||||
getsize = liftIO $ fromIntegral . fileSize <$> getFileStatus file
|
getsize = liftIO $ fromIntegral . fileSize <$> getFileStatus file
|
||||||
|
|
||||||
xheaders = filter isxheader $ M.assocs $ fromJust $ config r
|
xheaders = filter isxheader $ M.assocs $ config r
|
||||||
isxheader (h, _) = "x-amz-" `isPrefixOf` h
|
isxheader (h, _) = "x-amz-" `isPrefixOf` h
|
||||||
|
|
||||||
retrieve :: Remote -> Key -> AssociatedFile -> FilePath -> Annex Bool
|
retrieve :: Remote -> Key -> AssociatedFile -> FilePath -> Annex Bool
|
||||||
|
@ -207,10 +204,8 @@ s3Bool (Left e) = s3Warning e
|
||||||
|
|
||||||
s3Action :: Remote -> a -> ((AWSConnection, String) -> Annex a) -> Annex a
|
s3Action :: Remote -> a -> ((AWSConnection, String) -> Annex a) -> Annex a
|
||||||
s3Action r noconn action = do
|
s3Action r noconn action = do
|
||||||
when (isNothing $ config r) $
|
let bucket = M.lookup "bucket" $ config r
|
||||||
error $ "Missing configuration for special remote " ++ name r
|
conn <- s3Connection (config r) (uuid r)
|
||||||
let bucket = M.lookup "bucket" $ fromJust $ config r
|
|
||||||
conn <- s3Connection (fromJust $ config r) (uuid r)
|
|
||||||
case (bucket, conn) of
|
case (bucket, conn) of
|
||||||
(Just b, Just c) -> action (c, b)
|
(Just b, Just c) -> action (c, b)
|
||||||
_ -> return noconn
|
_ -> return noconn
|
||||||
|
@ -222,7 +217,7 @@ bucketFile r = munge . key2file
|
||||||
Just "ia" -> iaMunge $ fileprefix ++ s
|
Just "ia" -> iaMunge $ fileprefix ++ s
|
||||||
_ -> fileprefix ++ s
|
_ -> fileprefix ++ s
|
||||||
fileprefix = M.findWithDefault "" "fileprefix" c
|
fileprefix = M.findWithDefault "" "fileprefix" c
|
||||||
c = fromJust $ config r
|
c = config r
|
||||||
|
|
||||||
bucketKey :: Remote -> String -> Key -> S3Object
|
bucketKey :: Remote -> String -> Key -> S3Object
|
||||||
bucketKey r bucket k = S3Object bucket (bucketFile r k) "" [] L.empty
|
bucketKey r bucket k = S3Object bucket (bucketFile r k) "" [] L.empty
|
||||||
|
|
|
@ -17,6 +17,8 @@ import Logs.Web
|
||||||
import qualified Utility.Url as Url
|
import qualified Utility.Url as Url
|
||||||
import Types.Key
|
import Types.Key
|
||||||
|
|
||||||
|
import qualified Data.Map as M
|
||||||
|
|
||||||
remote :: RemoteType
|
remote :: RemoteType
|
||||||
remote = RemoteType {
|
remote = RemoteType {
|
||||||
typename = "web",
|
typename = "web",
|
||||||
|
@ -33,7 +35,7 @@ list = do
|
||||||
r <- liftIO $ Git.Construct.remoteNamed "web" Git.Construct.fromUnknown
|
r <- liftIO $ Git.Construct.remoteNamed "web" Git.Construct.fromUnknown
|
||||||
return [r]
|
return [r]
|
||||||
|
|
||||||
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex Remote
|
gen :: Git.Repo -> UUID -> RemoteConfig -> Annex Remote
|
||||||
gen r _ _ =
|
gen r _ _ =
|
||||||
return Remote {
|
return Remote {
|
||||||
uuid = webUUID,
|
uuid = webUUID,
|
||||||
|
@ -46,7 +48,7 @@ gen r _ _ =
|
||||||
hasKey = checkKey,
|
hasKey = checkKey,
|
||||||
hasKeyCheap = False,
|
hasKeyCheap = False,
|
||||||
whereisKey = Just getUrls,
|
whereisKey = Just getUrls,
|
||||||
config = Nothing,
|
config = M.empty,
|
||||||
localpath = Nothing,
|
localpath = Nothing,
|
||||||
repo = r,
|
repo = r,
|
||||||
readonly = True,
|
readonly = True,
|
||||||
|
|
|
@ -45,34 +45,31 @@ remote = RemoteType {
|
||||||
setup = webdavSetup
|
setup = webdavSetup
|
||||||
}
|
}
|
||||||
|
|
||||||
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex Remote
|
gen :: Git.Repo -> UUID -> RemoteConfig -> Annex Remote
|
||||||
gen r u c = do
|
gen r u c = new <$> remoteCost r expensiveRemoteCost
|
||||||
cst <- remoteCost r expensiveRemoteCost
|
where
|
||||||
return $ gen' r u c cst
|
new cst = encryptableRemote c
|
||||||
gen' :: Git.Repo -> UUID -> Maybe RemoteConfig -> Int -> Remote
|
|
||||||
gen' r u c cst =
|
|
||||||
encryptableRemote c
|
|
||||||
(storeEncrypted this)
|
(storeEncrypted this)
|
||||||
(retrieveEncrypted this)
|
(retrieveEncrypted this)
|
||||||
this
|
this
|
||||||
where
|
where
|
||||||
this = Remote {
|
this = Remote {
|
||||||
uuid = u,
|
uuid = u,
|
||||||
cost = cst,
|
cost = cst,
|
||||||
name = Git.repoDescribe r,
|
name = Git.repoDescribe r,
|
||||||
storeKey = store this,
|
storeKey = store this,
|
||||||
retrieveKeyFile = retrieve this,
|
retrieveKeyFile = retrieve this,
|
||||||
retrieveKeyFileCheap = retrieveCheap this,
|
retrieveKeyFileCheap = retrieveCheap this,
|
||||||
removeKey = remove this,
|
removeKey = remove this,
|
||||||
hasKey = checkPresent this,
|
hasKey = checkPresent this,
|
||||||
hasKeyCheap = False,
|
hasKeyCheap = False,
|
||||||
whereisKey = Nothing,
|
whereisKey = Nothing,
|
||||||
config = c,
|
config = c,
|
||||||
repo = r,
|
repo = r,
|
||||||
localpath = Nothing,
|
localpath = Nothing,
|
||||||
readonly = False,
|
readonly = False,
|
||||||
remotetype = remote
|
remotetype = remote
|
||||||
}
|
}
|
||||||
|
|
||||||
webdavSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
webdavSetup :: UUID -> RemoteConfig -> Annex RemoteConfig
|
||||||
webdavSetup u c = do
|
webdavSetup u c = do
|
||||||
|
@ -201,14 +198,12 @@ withStoredFiles r k baseurl user pass onerr a
|
||||||
keyurl = davLocation baseurl k ++ keyFile k
|
keyurl = davLocation baseurl k ++ keyFile k
|
||||||
|
|
||||||
davAction :: Remote -> a -> ((DavUrl, DavUser, DavPass) -> Annex a) -> Annex a
|
davAction :: Remote -> a -> ((DavUrl, DavUser, DavPass) -> Annex a) -> Annex a
|
||||||
davAction r unconfigured action = case config r of
|
davAction r unconfigured action = do
|
||||||
Nothing -> return unconfigured
|
mcreds <- getCreds (config r) (uuid r)
|
||||||
Just c -> do
|
case (mcreds, M.lookup "url" $ config r) of
|
||||||
mcreds <- getCreds c (uuid r)
|
(Just (user, pass), Just url) ->
|
||||||
case (mcreds, M.lookup "url" c) of
|
action (url, toDavUser user, toDavPass pass)
|
||||||
(Just (user, pass), Just url) ->
|
_ -> return unconfigured
|
||||||
action (url, toDavUser user, toDavPass pass)
|
|
||||||
_ -> return unconfigured
|
|
||||||
|
|
||||||
toDavUser :: String -> DavUser
|
toDavUser :: String -> DavUser
|
||||||
toDavUser = B8.fromString
|
toDavUser = B8.fromString
|
||||||
|
|
|
@ -27,7 +27,7 @@ data RemoteTypeA a = RemoteType {
|
||||||
-- enumerates remotes of this type
|
-- enumerates remotes of this type
|
||||||
enumerate :: a [Git.Repo],
|
enumerate :: a [Git.Repo],
|
||||||
-- generates a remote of this type
|
-- generates a remote of this type
|
||||||
generate :: Git.Repo -> UUID -> Maybe RemoteConfig -> a (RemoteA a),
|
generate :: Git.Repo -> UUID -> RemoteConfig -> a (RemoteA a),
|
||||||
-- initializes or changes a remote
|
-- initializes or changes a remote
|
||||||
setup :: UUID -> RemoteConfig -> a RemoteConfig
|
setup :: UUID -> RemoteConfig -> a RemoteConfig
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,8 @@ data RemoteA a = Remote {
|
||||||
hasKeyCheap :: Bool,
|
hasKeyCheap :: Bool,
|
||||||
-- Some remotes can provide additional details for whereis.
|
-- Some remotes can provide additional details for whereis.
|
||||||
whereisKey :: Maybe (Key -> a [String]),
|
whereisKey :: Maybe (Key -> a [String]),
|
||||||
-- a Remote can have a persistent configuration store
|
-- a Remote has a persistent configuration store
|
||||||
config :: Maybe RemoteConfig,
|
config :: RemoteConfig,
|
||||||
-- git configuration for the remote
|
-- git configuration for the remote
|
||||||
repo :: Git.Repo,
|
repo :: Git.Repo,
|
||||||
-- a Remote can be assocated with a specific local filesystem path
|
-- a Remote can be assocated with a specific local filesystem path
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue