2010-10-10 17:47:04 +00:00
|
|
|
{- git-annex "url" backend
|
|
|
|
- -}
|
|
|
|
|
|
|
|
module BackendUrl (backend) where
|
|
|
|
|
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-12 21:26:34 +00:00
|
|
|
import IO
|
2010-10-12 20:06:10 +00:00
|
|
|
import Types
|
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,
|
|
|
|
removeKey = dummyRemove
|
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
|
|
|
|
dummyRemove :: Key -> Annex Bool
|
|
|
|
dummyRemove url = return False
|
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)
|
|
|
|
result <- liftIO $ try $ rawSystem "curl" ["-#", "-o", file, (show url)]
|
2010-10-12 21:26:34 +00:00
|
|
|
case (result) of
|
|
|
|
Left _ -> return False
|
|
|
|
Right _ -> return True
|