aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-07-01 18:46:07 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-07-01 18:59:40 -0400
commitace9de37e8db9c99db4b121392ca63091e48bfac (patch)
treeb3f790ea9bd184094aaf1561cbc7309391f5d1ba
parent5d154b84365770ff27c09137ad039f930505ebfd (diff)
download urls via tmp file, and support resuming
-rw-r--r--Command/AddUrl.hs16
-rw-r--r--Remote/Web.hs14
-rw-r--r--doc/todo/tahoe_lfs_for_reals/comment_2_80b9e848edfdc7be21baab7d0cef0e3a._comment3
3 files changed, 23 insertions, 10 deletions
diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs
index 713a486a5..ebf0810ba 100644
--- a/Command/AddUrl.hs
+++ b/Command/AddUrl.hs
@@ -16,9 +16,13 @@ import Command
import qualified Backend
import qualified Remote.Web
import qualified Command.Add
+import qualified Annex
import Messages
import Content
import PresenceLog
+import Types.Key
+import Locations
+import Utility
command :: [Command]
command = [repoCommand "addurl" paramPath seek "add urls to annex"]
@@ -38,16 +42,20 @@ start s = do
perform :: String -> FilePath -> CommandPerform
perform url file = do
- [(_, backend)] <- Backend.chooseBackends [file]
+ g <- Annex.gitRepo
showNote $ "downloading " ++ url
- ok <- Remote.Web.download file [url]
+ let dummykey = stubKey { keyName = url, keyBackendName = "URL" }
+ let tmp = gitAnnexTmpLocation g dummykey
+ liftIO $ createDirectoryIfMissing True (parentDir tmp)
+ ok <- Remote.Web.download [url] tmp
if ok
then do
- stored <- Backend.storeFileKey file backend
+ [(_, backend)] <- Backend.chooseBackends [file]
+ stored <- Backend.storeFileKey tmp backend
case stored of
Nothing -> stop
Just (key, _) -> do
- moveAnnex key file
+ moveAnnex key tmp
Remote.Web.setUrl key url InfoPresent
next $ Command.Add.cleanup file key
else stop
diff --git a/Remote/Web.hs b/Remote/Web.hs
index 7425dec87..304f191d3 100644
--- a/Remote/Web.hs
+++ b/Remote/Web.hs
@@ -82,7 +82,9 @@ setUrl key url status = do
logChange g key webUUID (if null us then InfoMissing else InfoPresent)
downloadKey :: Key -> FilePath -> Annex Bool
-downloadKey key file = download file =<< getUrls key
+downloadKey key file = do
+ us <- getUrls key
+ download us file
uploadKey :: Key -> Annex Bool
uploadKey _ = do
@@ -116,9 +118,9 @@ urlexists url = do
res <- perform curl
return $ res == CurlOK
-download :: FilePath -> [URLString] -> Annex Bool
-download _ [] = return False
-download file (url:us) = do
+download :: [URLString] -> FilePath -> Annex Bool
+download [] _ = return False
+download (url:us) file = do
showProgress -- make way for curl progress bar
- ok <- liftIO $ boolSystem "curl" [Params "-# -o", File file, File url]
- if ok then return ok else download file us
+ ok <- liftIO $ boolSystem "curl" [Params "-C - -# -o", File file, File url]
+ if ok then return ok else download us file
diff --git a/doc/todo/tahoe_lfs_for_reals/comment_2_80b9e848edfdc7be21baab7d0cef0e3a._comment b/doc/todo/tahoe_lfs_for_reals/comment_2_80b9e848edfdc7be21baab7d0cef0e3a._comment
index a32461615..6dba86c47 100644
--- a/doc/todo/tahoe_lfs_for_reals/comment_2_80b9e848edfdc7be21baab7d0cef0e3a._comment
+++ b/doc/todo/tahoe_lfs_for_reals/comment_2_80b9e848edfdc7be21baab7d0cef0e3a._comment
@@ -7,4 +7,7 @@
Whoops! You'd only told me O(N) twice before..
So this is not too high priority. I think I would like to get the per-remote storage sorted out anyway, since probably it will be the thing needed to convert the URL backend into a special remote, which would then allow ripping out the otherwise unused pluggable backend infrastructure.
+
+Update: Per-remote storage is now sorted out, so this could be implemented
+if it actually made sense to do so.
"""]]