diff --git a/Logs/Web.hs b/Logs/Web.hs index 38993c33c7..b2935f1a0b 100644 --- a/Logs/Web.hs +++ b/Logs/Web.hs @@ -94,7 +94,7 @@ removeTempUrl key = Annex.changeState $ \s -> s { Annex.tempurls = M.delete key (Annex.tempurls s) } data Downloader = WebDownloader | QuviDownloader | OtherDownloader - deriving (Eq) + deriving (Eq, Show) {- To keep track of how an url is downloaded, it's mangled slightly in - the log. For quvi, "quvi:" is prefixed. For urls that are handled by diff --git a/Remote/External.hs b/Remote/External.hs index 0579400edb..7dd1736e45 100644 --- a/Remote/External.hs +++ b/Remote/External.hs @@ -223,6 +223,10 @@ handleRequest' lck external req mp responsehandler setUrlPresent (externalUUID external) key url handleRemoteRequest (SETURLMISSING key url) = setUrlMissing (externalUUID external) key url + handleRemoteRequest (SETURIPRESENT key uri) = + withurl (SETURLPRESENT key) uri + handleRemoteRequest (SETURIMISSING key uri) = + withurl (SETURLMISSING key) uri handleRemoteRequest (GETURLS key prefix) = do mapM_ (send . VALUE . fst . getDownloader) =<< getUrlsWithPrefix key prefix @@ -242,6 +246,9 @@ handleRequest' lck external req mp responsehandler } where base = replace "/" "_" $ fromUUID (externalUUID external) ++ "-" ++ setting + + withurl mk uri = handleRemoteRequest $ mk $ + setDownloader (show uri) OtherDownloader sendMessage :: Sendable m => ExternalLock -> External -> m -> Annex () sendMessage lck external m = diff --git a/Remote/External/Types.hs b/Remote/External/Types.hs index d0fb2ff7af..c7a28a3599 100644 --- a/Remote/External/Types.hs +++ b/Remote/External/Types.hs @@ -43,6 +43,7 @@ import Utility.Url (URLString) import qualified Utility.SimpleProtocol as Proto import Control.Concurrent.STM +import Network.URI -- If the remote is not yet running, the ExternalState TMVar is empty. data External = External @@ -182,6 +183,8 @@ data RemoteRequest | GETSTATE Key | SETURLPRESENT Key URLString | SETURLMISSING Key URLString + | SETURIPRESENT Key URI + | SETURIMISSING Key URI | GETURLS Key String | DEBUG String deriving (Show) @@ -202,6 +205,8 @@ instance Proto.Receivable RemoteRequest where parseCommand "GETSTATE" = Proto.parse1 GETSTATE parseCommand "SETURLPRESENT" = Proto.parse2 SETURLPRESENT parseCommand "SETURLMISSING" = Proto.parse2 SETURLMISSING + parseCommand "SETURIPRESENT" = Proto.parse2 SETURIPRESENT + parseCommand "SETURIMISSING" = Proto.parse2 SETURIMISSING parseCommand "GETURLS" = Proto.parse2 GETURLS parseCommand "DEBUG" = Proto.parse1 DEBUG parseCommand _ = Proto.parseFail @@ -288,3 +293,7 @@ instance Proto.Serializable [(URLString, Size, FilePath)] where where go c (url:sz:f:rest) = go ((url, readish sz, f):c) rest go c _ = reverse c + +instance Proto.Serializable URI where + serialize = show + deserialize = parseURI diff --git a/debian/changelog b/debian/changelog index 315bd8055a..05e2cadb9c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -29,6 +29,8 @@ git-annex (5.2015022) UNRELEASED; urgency=medium that contain unicode characters. * sync: Fix committing when in a direct mode repo that has no HEAD ref. (For example, a newly checked out git submodule.) + * Added SETURIPRESENT and SETURIMISSING to external special remote protocol, + useful for things like ipfs that don't use regular urls. -- Joey Hess Thu, 19 Feb 2015 14:16:03 -0400 diff --git a/doc/design/external_special_remote_protocol.mdwn b/doc/design/external_special_remote_protocol.mdwn index cc3bfce96b..0746a7be12 100644 --- a/doc/design/external_special_remote_protocol.mdwn +++ b/doc/design/external_special_remote_protocol.mdwn @@ -274,10 +274,19 @@ in control. Gets any state that has been stored for the key. (git-annex replies with VALUE followed by the state.) * `SETURLPRESENT Key Url` - Records an url (or uri) where the Key can be downloaded from. + Records an URL where the Key can be downloaded from. * `SETURLMISSING Key Url` Records that the key can no longer be downloaded from the specified - url (or uri). + URL. +* `SETURIPRESENT Key Uri` + Records a special URI where the Key can be downloaded from. + For example, "ipfs:ADDRESS" is used for the ipfs special remote; + its CLAIMURL handler checks for such URIS and claims them. Setting + it present as an URI makes `git annex whereis` display the URI + as belonging to the special remote. +* `SETURIMISSING Key Uri` + Records that the key can no longer be downloaded from the specified + URI. * `GETURLS Key Prefix` Gets the recorded urls where a Key can be downloaded from. Only urls that start with the Prefix will be returned. The Prefix diff --git a/doc/special_remotes/external/git-annex-remote-ipfs b/doc/special_remotes/external/git-annex-remote-ipfs index fc91aefc81..c8d97ef5c8 100755 --- a/doc/special_remotes/external/git-annex-remote-ipfs +++ b/doc/special_remotes/external/git-annex-remote-ipfs @@ -89,7 +89,7 @@ while read line; do if [ -z "$addr" ]; then echo TRANSFER-FAILURE STORE "$key" "ipfs add failed" else - echo "SETURLPRESENT" "$key" "$(addresstourl "$addr")" + echo "SETURIPRESENT" "$key" "$(addresstourl "$addr")" echo TRANSFER-SUCCESS STORE "$key" fi ;; diff --git a/doc/special_remotes/ipfs.mdwn b/doc/special_remotes/ipfs.mdwn index 42e92fde7a..5a31a2528f 100644 --- a/doc/special_remotes/ipfs.mdwn +++ b/doc/special_remotes/ipfs.mdwn @@ -7,8 +7,7 @@ keep your data safe while you're using ipfs. ## prerequisites -* git-annex version 5.20141219 or newer, which has [[external]] special remote - support. +* git-annex version 5.20150305 or newer. * Install [[external/git-annex-remote-ipfs]] somewhere in PATH and `chmod +x` the script. * Install [go-ipfs](https://github.com/jbenet/go-ipfs) somewhere in PATH.