2010-10-15 19:33:10 -04:00
|
|
|
{- git-annex "URL" backend
|
2010-10-27 16:53:54 -04:00
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
2010-10-10 13:47:04 -04:00
|
|
|
|
2011-03-02 13:47:45 -04:00
|
|
|
module Backend.URL (backends) where
|
2010-10-10 13:47:04 -04:00
|
|
|
|
2010-10-14 20:05:04 -04:00
|
|
|
import Control.Monad.State (liftIO)
|
2010-10-16 16:20:49 -04:00
|
|
|
|
2011-01-25 21:49:04 -04:00
|
|
|
import Types
|
2011-03-15 22:04:50 -04:00
|
|
|
import BackendClass
|
2010-10-29 14:07:26 -04:00
|
|
|
import Utility
|
2010-11-08 15:15:21 -04:00
|
|
|
import Messages
|
2011-03-15 22:28:18 -04:00
|
|
|
import Key
|
2010-10-10 13:47:04 -04:00
|
|
|
|
2011-03-02 13:47:45 -04:00
|
|
|
backends :: [Backend Annex]
|
|
|
|
backends = [backend]
|
|
|
|
|
2011-01-25 21:02:34 -04:00
|
|
|
backend :: Backend Annex
|
2010-10-10 13:47:04 -04:00
|
|
|
backend = Backend {
|
2010-10-15 19:33:10 -04:00
|
|
|
name = "URL",
|
2010-10-10 15:04:18 -04:00
|
|
|
getKey = keyValue,
|
|
|
|
storeFileKey = dummyStore,
|
2010-10-10 19:53:31 -04:00
|
|
|
retrieveKeyFile = downloadUrl,
|
2010-11-13 14:59:27 -04:00
|
|
|
-- allow keys to be removed; presumably they can always be
|
|
|
|
-- downloaded again
|
2010-11-28 15:28:20 -04:00
|
|
|
removeKey = dummyRemove,
|
2010-11-13 14:59:27 -04:00
|
|
|
-- similarly, keys are always assumed to be out there on the web
|
|
|
|
hasKey = dummyOk,
|
|
|
|
-- and nothing needed to fsck
|
2011-03-23 17:57:10 -04:00
|
|
|
fsckKey = dummyFsck,
|
|
|
|
-- and key upgrade not needed
|
|
|
|
upgradableKey = \_ -> return False
|
2010-10-10 13:47:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
-- cannot generate url from filename
|
2010-10-13 21:28:47 -04:00
|
|
|
keyValue :: FilePath -> Annex (Maybe Key)
|
2010-10-31 16:00:32 -04:00
|
|
|
keyValue _ = return Nothing
|
2010-10-10 13:47:04 -04:00
|
|
|
|
2010-10-12 17:26:34 -04:00
|
|
|
-- cannot change url contents
|
2010-10-13 21:28:47 -04:00
|
|
|
dummyStore :: FilePath -> Key -> Annex Bool
|
2010-10-31 16:00:32 -04:00
|
|
|
dummyStore _ _ = return False
|
2010-10-14 14:14:19 -04:00
|
|
|
|
2010-11-28 15:28:20 -04:00
|
|
|
dummyRemove :: Key -> Maybe a -> Annex Bool
|
2011-03-17 11:49:21 -04:00
|
|
|
dummyRemove _ _ = return True
|
2010-11-28 15:28:20 -04:00
|
|
|
|
2011-01-26 20:37:46 -04:00
|
|
|
dummyFsck :: Key -> Maybe FilePath -> Maybe a -> Annex Bool
|
|
|
|
dummyFsck _ _ _ = return True
|
2010-11-28 15:28:20 -04:00
|
|
|
|
2010-10-14 15:31:44 -04:00
|
|
|
dummyOk :: Key -> Annex Bool
|
2010-10-31 16:00:32 -04:00
|
|
|
dummyOk _ = return True
|
2010-10-10 15:04:18 -04:00
|
|
|
|
2010-10-13 21:28:47 -04:00
|
|
|
downloadUrl :: Key -> FilePath -> Annex Bool
|
2010-10-14 20:05:04 -04:00
|
|
|
downloadUrl key file = do
|
2011-03-15 22:28:18 -04:00
|
|
|
showNote $ "downloading"
|
2010-10-29 14:10:55 -04:00
|
|
|
showProgress -- make way for curl progress bar
|
2011-02-28 16:10:16 -04:00
|
|
|
liftIO $ boolSystem "curl" [Params "-# -o", File file, File url]
|
2010-10-14 20:05:04 -04:00
|
|
|
where
|
2011-03-15 22:28:18 -04:00
|
|
|
url = keyName key
|