summaryrefslogtreecommitdiff
path: root/Backend/Url.hs
blob: e23767208497f1109b4233c984d8dab4e3c519d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{- git-annex "url" backend
 - -}

module Backend.Url (backend) where

import Control.Monad.State (liftIO)
import Data.String.Utils
import System.Cmd
import System.Exit
import BackendTypes

backend = Backend {
	name = "url",
	getKey = keyValue,
	storeFileKey = dummyStore,
	retrieveKeyFile = downloadUrl,
	removeKey = dummyOk,
	hasKey = dummyOk
}

-- cannot generate url from filename
keyValue :: FilePath -> Annex (Maybe Key)
keyValue file = return Nothing

-- cannot change url contents
dummyStore :: FilePath -> Key -> Annex Bool
dummyStore file url = return False

-- allow keys to be removed; presumably they can always be downloaded again
dummyOk :: Key -> Annex Bool
dummyOk url = return True

downloadUrl :: Key -> FilePath -> Annex Bool
downloadUrl key file = do
	liftIO $ putStrLn $ "download: " ++ url
	result <- liftIO $ rawSystem "curl" ["-#", "-o", file, url]
	if (result == ExitSuccess)
		then return True
		else return False
	where
		url = join ":" $ drop 1 $ split ":" $ show key