2011-07-01 15:24:07 -04:00
|
|
|
{- Web remotes.
|
|
|
|
-
|
|
|
|
- Copyright 2011 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2011-10-15 16:36:56 -04:00
|
|
|
module Remote.Web (remote) where
|
2011-07-01 15:24:07 -04:00
|
|
|
|
2011-10-05 16:02:51 -04:00
|
|
|
import Common.Annex
|
2011-07-01 15:24:07 -04:00
|
|
|
import Types.Remote
|
|
|
|
import qualified Git
|
2011-12-13 15:05:07 -04:00
|
|
|
import qualified Git.Construct
|
2012-01-02 14:20:20 -04:00
|
|
|
import Annex.Content
|
2011-07-01 15:24:07 -04:00
|
|
|
import Config
|
2011-10-15 16:25:51 -04:00
|
|
|
import Logs.Web
|
2011-08-20 16:11:42 -04:00
|
|
|
import qualified Utility.Url as Url
|
2012-02-10 19:17:41 -04:00
|
|
|
import Types.Key
|
2011-07-01 15:24:07 -04:00
|
|
|
|
2011-12-31 04:11:39 -04:00
|
|
|
remote :: RemoteType
|
2011-07-01 15:24:07 -04:00
|
|
|
remote = RemoteType {
|
|
|
|
typename = "web",
|
|
|
|
enumerate = list,
|
|
|
|
generate = gen,
|
|
|
|
setup = error "not supported"
|
|
|
|
}
|
|
|
|
|
|
|
|
-- There is only one web remote, and it always exists.
|
|
|
|
-- (If the web should cease to exist, remove this module and redistribute
|
|
|
|
-- a new release to the survivors by carrier pigeon.)
|
|
|
|
list :: Annex [Git.Repo]
|
2011-12-14 15:30:14 -04:00
|
|
|
list = do
|
|
|
|
r <- liftIO $ Git.Construct.remoteNamed "web" Git.Construct.fromUnknown
|
|
|
|
return [r]
|
2011-07-01 15:24:07 -04:00
|
|
|
|
2011-12-31 04:11:39 -04:00
|
|
|
gen :: Git.Repo -> UUID -> Maybe RemoteConfig -> Annex Remote
|
2011-07-01 15:24:07 -04:00
|
|
|
gen r _ _ =
|
2011-07-15 12:47:14 -04:00
|
|
|
return Remote {
|
2011-07-01 15:24:07 -04:00
|
|
|
uuid = webUUID,
|
|
|
|
cost = expensiveRemoteCost,
|
|
|
|
name = Git.repoDescribe r,
|
2011-07-01 17:15:46 -04:00
|
|
|
storeKey = uploadKey,
|
|
|
|
retrieveKeyFile = downloadKey,
|
2012-01-20 13:23:11 -04:00
|
|
|
retrieveKeyFileCheap = downloadKeyCheap,
|
2011-07-01 17:15:46 -04:00
|
|
|
removeKey = dropKey,
|
|
|
|
hasKey = checkKey,
|
2011-07-01 15:24:07 -04:00
|
|
|
hasKeyCheap = False,
|
2012-02-14 03:49:48 -04:00
|
|
|
whereisKey = Just getUrls,
|
2011-09-18 20:11:39 -04:00
|
|
|
config = Nothing,
|
2011-12-31 03:27:37 -04:00
|
|
|
repo = r,
|
|
|
|
remotetype = remote
|
2011-07-01 15:24:07 -04:00
|
|
|
}
|
|
|
|
|
2012-01-20 13:23:11 -04:00
|
|
|
downloadKey :: Key -> FilePath -> Annex Bool
|
|
|
|
downloadKey key file = get =<< getUrls key
|
2011-08-16 20:49:04 -04:00
|
|
|
where
|
2011-08-27 07:08:15 -04:00
|
|
|
get [] = do
|
|
|
|
warning "no known url"
|
|
|
|
return False
|
2011-10-16 00:04:26 -04:00
|
|
|
get urls = do
|
|
|
|
showOutput -- make way for download progress bar
|
2012-01-02 14:20:20 -04:00
|
|
|
downloadUrl urls file
|
2011-07-01 15:24:07 -04:00
|
|
|
|
2012-01-20 13:23:11 -04:00
|
|
|
downloadKeyCheap :: Key -> FilePath -> Annex Bool
|
|
|
|
downloadKeyCheap _ _ = return False
|
|
|
|
|
2011-07-01 17:15:46 -04:00
|
|
|
uploadKey :: Key -> Annex Bool
|
|
|
|
uploadKey _ = do
|
2011-07-01 15:24:07 -04:00
|
|
|
warning "upload to web not supported"
|
|
|
|
return False
|
|
|
|
|
2011-07-01 17:15:46 -04:00
|
|
|
dropKey :: Key -> Annex Bool
|
|
|
|
dropKey _ = do
|
2011-07-01 15:24:07 -04:00
|
|
|
warning "removal from web not supported"
|
|
|
|
return False
|
|
|
|
|
2011-11-09 18:33:15 -04:00
|
|
|
checkKey :: Key -> Annex (Either String Bool)
|
2011-07-01 17:15:46 -04:00
|
|
|
checkKey key = do
|
|
|
|
us <- getUrls key
|
2011-07-01 15:24:07 -04:00
|
|
|
if null us
|
|
|
|
then return $ Right False
|
2012-02-10 19:17:41 -04:00
|
|
|
else return . Right =<< checkKey' key us
|
|
|
|
checkKey' :: Key -> [URLString] -> Annex Bool
|
|
|
|
checkKey' key us = untilTrue us $ \u -> do
|
2011-07-19 14:07:23 -04:00
|
|
|
showAction $ "checking " ++ u
|
2012-02-10 19:17:41 -04:00
|
|
|
liftIO $ Url.check u (keySize key)
|