summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Annex.hs10
-rw-r--r--Backend.hs2
-rw-r--r--BackendUrl.hs11
3 files changed, 18 insertions, 5 deletions
diff --git a/Annex.hs b/Annex.hs
index 7ac9932f1..68379cf20 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -14,6 +14,7 @@ module Annex (
import System.Posix.Files
import System.Directory
+import Data.String.Utils
import GitRepo
import Utility
import Locations
@@ -23,9 +24,14 @@ import UUID
import LocationLog
import Types
-{- An annexed file's content is stored somewhere under .git/annex/ -}
+{- An annexed file's content is stored somewhere under .git/annex/,
+ - based on the key. Since the symlink is user-visible, the filename
+ - used should be as close to the key as possible, in case the key is a
+ - filename or url. Just escape "/" in the key name, to keep a flat
+ - tree of files and avoid issues with files ending with "/" etc. -}
annexLocation :: GitRepo -> Key -> FilePath
-annexLocation repo key = gitDir repo ++ "/annex/" ++ key
+annexLocation repo key = gitDir repo ++ "/annex/" ++ (transform key)
+ where transform s = replace "/" "%" $ replace "%" "%%" s
{- On startup, examine the git repo, prepare it, and record state for
- later. -}
diff --git a/Backend.hs b/Backend.hs
index 9d1b0cdbe..a16dfab6a 100644
--- a/Backend.hs
+++ b/Backend.hs
@@ -102,7 +102,7 @@ lookupKey state backend file = do
k <- readFile (backendFile state backend file)
return $ chomp k
where
- chomp s = if (endswith s "\n")
+ chomp s = if (endswith "\n" s)
then (reverse . (drop 1) . reverse) s
else s
diff --git a/BackendUrl.hs b/BackendUrl.hs
index 71503c5c1..ca44a5c37 100644
--- a/BackendUrl.hs
+++ b/BackendUrl.hs
@@ -3,6 +3,8 @@
module BackendUrl (backend) where
+import System.Posix.Process
+import IO
import Types
backend = Backend {
@@ -17,11 +19,16 @@ backend = Backend {
keyValue :: State -> FilePath -> IO (Maybe Key)
keyValue repo file = return Nothing
--- cannot change urls
+-- cannot change url contents
dummyStore :: State -> FilePath -> Key -> IO Bool
dummyStore repo file url = return False
dummyRemove :: State -> Key -> IO Bool
dummyRemove state url = return False
downloadUrl :: State -> Key -> FilePath -> IO Bool
-downloadUrl state url file = error "downloadUrl unimplemented"
+downloadUrl state url file = do
+ putStrLn $ "download: " ++ url
+ result <- try $ executeFile "curl" True ["-o", file, url] Nothing
+ case (result) of
+ Left _ -> return False
+ Right _ -> return True