2012-04-17 22:37:40 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2012-01-10 17:11:16 +00:00
|
|
|
{- git-annex remote list
|
|
|
|
-
|
2012-07-22 17:48:50 +00:00
|
|
|
- Copyright 2011,2012 Joey Hess <joey@kitenet.net>
|
2012-01-10 17:11:16 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Remote.List where
|
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import qualified Annex
|
|
|
|
import Logs.Remote
|
|
|
|
import Types.Remote
|
2013-01-01 17:52:47 +00:00
|
|
|
import Types.GitConfig
|
2012-01-10 17:11:16 +00:00
|
|
|
import Annex.UUID
|
2012-03-04 20:00:24 +00:00
|
|
|
import Remote.Helper.Hooks
|
2012-07-22 17:48:50 +00:00
|
|
|
import qualified Git
|
2012-08-05 18:49:47 +00:00
|
|
|
import qualified Git.Config
|
2012-01-10 17:11:16 +00:00
|
|
|
|
|
|
|
import qualified Remote.Git
|
2012-04-14 18:22:33 +00:00
|
|
|
#ifdef WITH_S3
|
2012-02-14 07:10:01 +00:00
|
|
|
import qualified Remote.S3
|
2012-04-14 18:22:33 +00:00
|
|
|
#endif
|
2012-01-10 17:11:16 +00:00
|
|
|
import qualified Remote.Bup
|
|
|
|
import qualified Remote.Directory
|
|
|
|
import qualified Remote.Rsync
|
|
|
|
import qualified Remote.Web
|
2012-11-15 00:25:00 +00:00
|
|
|
#ifdef WITH_WEBDAV
|
|
|
|
import qualified Remote.WebDAV
|
|
|
|
#endif
|
2012-11-20 20:43:58 +00:00
|
|
|
import qualified Remote.Glacier
|
2012-01-10 17:11:16 +00:00
|
|
|
import qualified Remote.Hook
|
|
|
|
|
|
|
|
remoteTypes :: [RemoteType]
|
|
|
|
remoteTypes =
|
|
|
|
[ Remote.Git.remote
|
2012-04-14 18:22:33 +00:00
|
|
|
#ifdef WITH_S3
|
2012-02-14 07:10:01 +00:00
|
|
|
, Remote.S3.remote
|
2012-04-14 18:22:33 +00:00
|
|
|
#endif
|
2012-01-10 17:11:16 +00:00
|
|
|
, Remote.Bup.remote
|
|
|
|
, Remote.Directory.remote
|
|
|
|
, Remote.Rsync.remote
|
|
|
|
, Remote.Web.remote
|
2012-11-15 00:25:00 +00:00
|
|
|
#ifdef WITH_WEBDAV
|
|
|
|
, Remote.WebDAV.remote
|
|
|
|
#endif
|
2012-11-20 20:43:58 +00:00
|
|
|
, Remote.Glacier.remote
|
2012-01-10 17:11:16 +00:00
|
|
|
, Remote.Hook.remote
|
|
|
|
]
|
|
|
|
|
|
|
|
{- Builds a list of all available Remotes.
|
|
|
|
- Since doing so can be expensive, the list is cached. -}
|
|
|
|
remoteList :: Annex [Remote]
|
|
|
|
remoteList = do
|
|
|
|
rs <- Annex.getState Annex.remotes
|
|
|
|
if null rs
|
|
|
|
then do
|
|
|
|
m <- readRemoteLog
|
|
|
|
rs' <- concat <$> mapM (process m) remoteTypes
|
|
|
|
Annex.changeState $ \s -> s { Annex.remotes = rs' }
|
|
|
|
return rs'
|
|
|
|
else return rs
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
|
|
|
process m t = enumerate t >>= mapM (remoteGen m t)
|
2012-07-22 17:48:50 +00:00
|
|
|
|
2012-08-05 18:49:47 +00:00
|
|
|
{- Forces the remoteList to be re-generated, re-reading the git config. -}
|
|
|
|
remoteListRefresh :: Annex [Remote]
|
|
|
|
remoteListRefresh = do
|
|
|
|
newg <- inRepo Git.Config.reRead
|
|
|
|
Annex.changeState $ \s -> s
|
|
|
|
{ Annex.remotes = []
|
|
|
|
, Annex.repo = newg
|
|
|
|
}
|
|
|
|
remoteList
|
|
|
|
|
2012-07-22 17:48:50 +00:00
|
|
|
{- Generates a Remote. -}
|
|
|
|
remoteGen :: (M.Map UUID RemoteConfig) -> RemoteType -> Git.Repo -> Annex Remote
|
|
|
|
remoteGen m t r = do
|
|
|
|
u <- getRepoUUID r
|
2013-01-01 17:52:47 +00:00
|
|
|
g <- fromRepo id
|
|
|
|
let gc = extractRemoteGitConfig g (Git.repoDescribe r)
|
|
|
|
let c = fromMaybe M.empty $ M.lookup u m
|
|
|
|
addHooks <$> generate t r u c gc
|
2012-01-10 17:11:16 +00:00
|
|
|
|
2012-08-05 18:49:47 +00:00
|
|
|
{- Updates a local git Remote, re-reading its git config. -}
|
|
|
|
updateRemote :: Remote -> Annex Remote
|
|
|
|
updateRemote remote = do
|
|
|
|
m <- readRemoteLog
|
|
|
|
remote' <- updaterepo $ repo remote
|
|
|
|
remoteGen m (remotetype remote) remote'
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
|
|
|
updaterepo r
|
|
|
|
| Git.repoIsLocal r || Git.repoIsLocalUnknown r =
|
|
|
|
Remote.Git.configRead r
|
|
|
|
| otherwise = return r
|
2012-08-05 18:49:47 +00:00
|
|
|
|
2012-08-26 18:34:30 +00:00
|
|
|
{- Checks if a remote is a special remote -}
|
|
|
|
specialRemote :: Remote -> Bool
|
|
|
|
specialRemote r = remotetype r /= Remote.Git.remote
|