Added SETURIPRESENT and SETURIMISSING to external special remote protocol

Useful for things like ipfs that don't use regular urls.

An external special remote can add a regular url to a key, and then
git-annex get will download it from the web. But for ipfs, we want to
instead tell git-annex that the uri uses OtherDownloader. Before this
change, the external special remote protocol lacked a way to do that.
This commit is contained in:
Joey Hess 2015-03-05 13:50:15 -04:00
parent 9b4b190739
commit 6045406deb
7 changed files with 32 additions and 6 deletions

View file

@ -94,7 +94,7 @@ removeTempUrl key = Annex.changeState $ \s ->
s { Annex.tempurls = M.delete key (Annex.tempurls s) } s { Annex.tempurls = M.delete key (Annex.tempurls s) }
data Downloader = WebDownloader | QuviDownloader | OtherDownloader data Downloader = WebDownloader | QuviDownloader | OtherDownloader
deriving (Eq) deriving (Eq, Show)
{- To keep track of how an url is downloaded, it's mangled slightly in {- 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 - the log. For quvi, "quvi:" is prefixed. For urls that are handled by

View file

@ -223,6 +223,10 @@ handleRequest' lck external req mp responsehandler
setUrlPresent (externalUUID external) key url setUrlPresent (externalUUID external) key url
handleRemoteRequest (SETURLMISSING key url) = handleRemoteRequest (SETURLMISSING key url) =
setUrlMissing (externalUUID external) 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 handleRemoteRequest (GETURLS key prefix) = do
mapM_ (send . VALUE . fst . getDownloader) mapM_ (send . VALUE . fst . getDownloader)
=<< getUrlsWithPrefix key prefix =<< getUrlsWithPrefix key prefix
@ -242,6 +246,9 @@ handleRequest' lck external req mp responsehandler
} }
where where
base = replace "/" "_" $ fromUUID (externalUUID external) ++ "-" ++ setting base = replace "/" "_" $ fromUUID (externalUUID external) ++ "-" ++ setting
withurl mk uri = handleRemoteRequest $ mk $
setDownloader (show uri) OtherDownloader
sendMessage :: Sendable m => ExternalLock -> External -> m -> Annex () sendMessage :: Sendable m => ExternalLock -> External -> m -> Annex ()
sendMessage lck external m = sendMessage lck external m =

View file

@ -43,6 +43,7 @@ import Utility.Url (URLString)
import qualified Utility.SimpleProtocol as Proto import qualified Utility.SimpleProtocol as Proto
import Control.Concurrent.STM import Control.Concurrent.STM
import Network.URI
-- If the remote is not yet running, the ExternalState TMVar is empty. -- If the remote is not yet running, the ExternalState TMVar is empty.
data External = External data External = External
@ -182,6 +183,8 @@ data RemoteRequest
| GETSTATE Key | GETSTATE Key
| SETURLPRESENT Key URLString | SETURLPRESENT Key URLString
| SETURLMISSING Key URLString | SETURLMISSING Key URLString
| SETURIPRESENT Key URI
| SETURIMISSING Key URI
| GETURLS Key String | GETURLS Key String
| DEBUG String | DEBUG String
deriving (Show) deriving (Show)
@ -202,6 +205,8 @@ instance Proto.Receivable RemoteRequest where
parseCommand "GETSTATE" = Proto.parse1 GETSTATE parseCommand "GETSTATE" = Proto.parse1 GETSTATE
parseCommand "SETURLPRESENT" = Proto.parse2 SETURLPRESENT parseCommand "SETURLPRESENT" = Proto.parse2 SETURLPRESENT
parseCommand "SETURLMISSING" = Proto.parse2 SETURLMISSING parseCommand "SETURLMISSING" = Proto.parse2 SETURLMISSING
parseCommand "SETURIPRESENT" = Proto.parse2 SETURIPRESENT
parseCommand "SETURIMISSING" = Proto.parse2 SETURIMISSING
parseCommand "GETURLS" = Proto.parse2 GETURLS parseCommand "GETURLS" = Proto.parse2 GETURLS
parseCommand "DEBUG" = Proto.parse1 DEBUG parseCommand "DEBUG" = Proto.parse1 DEBUG
parseCommand _ = Proto.parseFail parseCommand _ = Proto.parseFail
@ -288,3 +293,7 @@ instance Proto.Serializable [(URLString, Size, FilePath)] where
where where
go c (url:sz:f:rest) = go ((url, readish sz, f):c) rest go c (url:sz:f:rest) = go ((url, readish sz, f):c) rest
go c _ = reverse c go c _ = reverse c
instance Proto.Serializable URI where
serialize = show
deserialize = parseURI

2
debian/changelog vendored
View file

@ -29,6 +29,8 @@ git-annex (5.2015022) UNRELEASED; urgency=medium
that contain unicode characters. that contain unicode characters.
* sync: Fix committing when in a direct mode repo that has no HEAD ref. * sync: Fix committing when in a direct mode repo that has no HEAD ref.
(For example, a newly checked out git submodule.) (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 <id@joeyh.name> Thu, 19 Feb 2015 14:16:03 -0400 -- Joey Hess <id@joeyh.name> Thu, 19 Feb 2015 14:16:03 -0400

View file

@ -274,10 +274,19 @@ in control.
Gets any state that has been stored for the key. Gets any state that has been stored for the key.
(git-annex replies with VALUE followed by the state.) (git-annex replies with VALUE followed by the state.)
* `SETURLPRESENT Key Url` * `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` * `SETURLMISSING Key Url`
Records that the key can no longer be downloaded from the specified 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` * `GETURLS Key Prefix`
Gets the recorded urls where a Key can be downloaded from. Gets the recorded urls where a Key can be downloaded from.
Only urls that start with the Prefix will be returned. The Prefix Only urls that start with the Prefix will be returned. The Prefix

View file

@ -89,7 +89,7 @@ while read line; do
if [ -z "$addr" ]; then if [ -z "$addr" ]; then
echo TRANSFER-FAILURE STORE "$key" "ipfs add failed" echo TRANSFER-FAILURE STORE "$key" "ipfs add failed"
else else
echo "SETURLPRESENT" "$key" "$(addresstourl "$addr")" echo "SETURIPRESENT" "$key" "$(addresstourl "$addr")"
echo TRANSFER-SUCCESS STORE "$key" echo TRANSFER-SUCCESS STORE "$key"
fi fi
;; ;;

View file

@ -7,8 +7,7 @@ keep your data safe while you're using ipfs.
## prerequisites ## prerequisites
* git-annex version 5.20141219 or newer, which has [[external]] special remote * git-annex version 5.20150305 or newer.
support.
* Install [[external/git-annex-remote-ipfs]] somewhere in PATH * Install [[external/git-annex-remote-ipfs]] somewhere in PATH
and `chmod +x` the script. and `chmod +x` the script.
* Install [go-ipfs](https://github.com/jbenet/go-ipfs) somewhere in PATH. * Install [go-ipfs](https://github.com/jbenet/go-ipfs) somewhere in PATH.