2010-10-10 17:47:04 +00:00
|
|
|
{- git-annex "url" backend
|
|
|
|
- -}
|
|
|
|
|
2010-10-14 07:50:28 +00:00
|
|
|
module Backend.Url (backend) where
|
2010-10-10 17:47:04 +00:00
|
|
|
|
2010-10-14 01:28:47 +00:00
|
|
|
import Control.Monad.State
|
2010-10-12 21:43:54 +00:00
|
|
|
import System.Cmd
|
2010-10-14 17:17:43 +00:00
|
|
|
import System.Exit
|
2010-10-14 06:52:17 +00:00
|
|
|
import BackendTypes
|
2010-10-10 17:47:04 +00:00
|
|
|
|
|
|
|
backend = Backend {
|
|
|
|
name = "url",
|
2010-10-10 19:04:18 +00:00
|
|
|
getKey = keyValue,
|
|
|
|
storeFileKey = dummyStore,
|
2010-10-10 23:53:31 +00:00
|
|
|
retrieveKeyFile = downloadUrl,
|
2010-10-14 19:31:44 +00:00
|
|
|
removeKey = dummyOk,
|
|
|
|
hasKey = dummyOk
|
2010-10-10 17:47:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- cannot generate url from filename
|
2010-10-14 01:28:47 +00:00
|
|
|
keyValue :: FilePath -> Annex (Maybe Key)
|
|
|
|
keyValue file = return Nothing
|
2010-10-10 17:47:04 +00:00
|
|
|
|
2010-10-12 21:26:34 +00:00
|
|
|
-- cannot change url contents
|
2010-10-14 01:28:47 +00:00
|
|
|
dummyStore :: FilePath -> Key -> Annex Bool
|
|
|
|
dummyStore file url = return False
|
2010-10-14 18:14:19 +00:00
|
|
|
|
2010-10-14 19:31:44 +00:00
|
|
|
-- allow keys to be removed; presumably they can always be downloaded again
|
|
|
|
dummyOk :: Key -> Annex Bool
|
|
|
|
dummyOk url = return True
|
2010-10-10 19:04:18 +00:00
|
|
|
|
2010-10-14 01:28:47 +00:00
|
|
|
downloadUrl :: Key -> FilePath -> Annex Bool
|
|
|
|
downloadUrl url file = do
|
|
|
|
liftIO $ putStrLn $ "download: " ++ (show url)
|
2010-10-14 17:17:43 +00:00
|
|
|
result <- liftIO $ rawSystem "curl" ["-#", "-o", file, (show url)]
|
|
|
|
if (result == ExitSuccess)
|
|
|
|
then return True
|
|
|
|
else return False
|