Skip to content

Support TRANSFER-RETRIEVE-URL extension #120

@mih

Description

@mih

This is a recent addition (https://git-annex.branchable.com/news/version_10.20251215/). See https://git-annex.branchable.com/todo/Special_remote_redirect_to_URL/ for more information.

This is a very useful feature, because it allows special remote implementations to leave all download handling to git-annex itself, which avoid redundant implementations and is likely to yield more secure and more coherent behavior.

At the moment only non-export retrieval is supported. In the TODO item listed above a few possible future directions are mentioned.

Looking at the code, it appears that support for this feature would need to be added to

def do_TRANSFER(self, param):
try:
(method, key, file_) = param.split(" ", 2)
except ValueError:
raise SyntaxError("Expected Key File")
if not (method == "STORE" or method == "RETRIEVE"):
return self.do_UNKNOWN()
func = getattr(self.remote, "transfer_{}".format(method.lower()), None)
try:
func(key, file_)
except RemoteError as e:
return "TRANSFER-FAILURE {method} {key} {e}".format(
method=method, key=key, e=e
)
else:
return "TRANSFER-SUCCESS {method} {key}".format(method=method, key=key)

One approach would be to support a return value for func(). If a non-None return value is observed, a

TRANSFER-RETRIEVE-URL Key <return-value>

response would be produced (rather than TRANSFER-SUCCESS).

However, this is a bit convoluted, because do_TRANSFER handles any transfer, not just retrieval.

An alternative approach would be to support a dedicated exception RetrievalRedirect(Exception), and have the above logic be triggered by this exception.

Personally, I am leaning towards implementing an approach with a conditional code path in the else branch at

else:
return "TRANSFER-SUCCESS {method} {key}".format(method=method, key=key)
, evaluating a return value. Something like:

else:
    if "TRANSFER-RETRIEVE-URL" in self.protocol.extensions and method == "RETRIEVE" and _ret:
        return "TRANSFER-RETRIEVE-URL {key} {url}".format(key=key, url=_ret)
    else:
        return "TRANSFER-SUCCESS {method} {key}".format(method=method, key=key)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions