summaryrefslogtreecommitdiff
path: root/Command/AddUrl.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-08-06 14:57:22 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-08-06 14:57:22 -0400
commitdede05171bc9431778da72e5e1235c69db9fa38e (patch)
treea9bc1f6fce6e16af835b9d3ff7d647ad0d82583e /Command/AddUrl.hs
parentdd8e649f49212c46df23f329299c64e13a3c90e1 (diff)
addurl: --fast can be used to avoid immediately downloading the url.
The tricky part about this is that to generate a key, the file must be present already. Worked around by adding (back) an URL key type, which is used for addurl --fast.
Diffstat (limited to 'Command/AddUrl.hs')
-rw-r--r--Command/AddUrl.hs27
1 files changed, 19 insertions, 8 deletions
diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs
index 1b12362e9..e87de384b 100644
--- a/Command/AddUrl.hs
+++ b/Command/AddUrl.hs
@@ -17,10 +17,10 @@ import qualified Backend
import qualified Remote.Web
import qualified Command.Add
import qualified Annex
+import qualified Backend.URL
import Messages
import Content
import PresenceLog
-import Types.Key
import Locations
import Utility
@@ -42,9 +42,14 @@ start s = do
perform :: String -> FilePath -> CommandPerform
perform url file = do
+ fast <- Annex.getState Annex.fast
+ if fast then nodownload url file else download url file
+
+download :: String -> FilePath -> CommandPerform
+download url file = do
g <- Annex.gitRepo
showAction $ "downloading " ++ url ++ " "
- let dummykey = stubKey { keyName = url, keyBackendName = "URL" }
+ let dummykey = Backend.URL.fromUrl url
let tmp = gitAnnexTmpLocation g dummykey
liftIO $ createDirectoryIfMissing True (parentDir tmp)
ok <- Remote.Web.download [url] tmp
@@ -57,9 +62,16 @@ perform url file = do
Just (key, _) -> do
moveAnnex key tmp
Remote.Web.setUrl key url InfoPresent
- next $ Command.Add.cleanup file key
+ next $ Command.Add.cleanup file key True
else stop
+nodownload :: String -> FilePath -> CommandPerform
+nodownload url file = do
+ let key = Backend.URL.fromUrl url
+ Remote.Web.setUrl key url InfoPresent
+
+ next $ Command.Add.cleanup file key False
+
url2file :: URI -> IO FilePath
url2file url = do
let parts = filter safe $ split "/" $ uriPath url
@@ -75,8 +87,7 @@ url2file url = do
e <- doesFileExist file
when e $ error "already have this url"
return file
- safe s
- | null s = False
- | s == "." = False
- | s == ".." = False
- | otherwise = True
+ safe "" = False
+ safe "." = False
+ safe ".." = False
+ safe _ = True