(Steve Dougherty)
2013-08-30: Set a path after resolving a push URI. Set a path after resolving a push URI. This is to avoid problems with deceptive nickname collisions when doing lookups without the full identity ID.
diff --git a/infocalypse/__init__.py b/infocalypse/__init__.py --- a/infocalypse/__init__.py +++ b/infocalypse/__init__.py @@ -602,7 +602,7 @@ def freenetpathtouri(ui, path, operation import wot if operation == "pull": truster = get_truster(ui, repo, truster_identifier) - return wot.resolve_pull_uri(ui, path, truster) + return wot.resolve_pull_uri(ui, path, truster, repo) elif operation == "push": return wot.resolve_push_uri(ui, path) elif operation == "clone-push": @@ -793,6 +793,8 @@ def freenetclone(orig, *args, **opts): infocalypse_create(ui, repo, local_identity, **opts) + # TODO: Function for adding paths? It's currently here, for pull, + # and in WoT pull URI resolution. with repo.opener("hgrc", "a", text=True) as f: f.write("""[paths] default-push = freenet:{0} diff --git a/infocalypse/commands.py b/infocalypse/commands.py --- a/infocalypse/commands.py +++ b/infocalypse/commands.py @@ -232,7 +232,7 @@ def infocalypse_pull(ui_, repo, **opts): import wot truster = get_truster(ui_, repo, opts['truster']) - request_uri = wot.resolve_pull_uri(ui_, opts['wot'], truster) + request_uri = wot.resolve_pull_uri(ui_, opts['wot'], truster, repo) elif opts['uri']: request_uri = parse_repo_path(opts['uri']) diff --git a/infocalypse/wot.py b/infocalypse/wot.py --- a/infocalypse/wot.py +++ b/infocalypse/wot.py @@ -392,7 +392,7 @@ def fetch_edition(uri): return node.get(str(uri), priority=1) -def resolve_pull_uri(ui, path, truster): +def resolve_pull_uri(ui, path, truster, repo=None): """ Return a pull URI for the given path. Print an error message and abort on failure. @@ -406,6 +406,7 @@ def resolve_pull_uri(ui, path, truster): :param ui: For feedback. :param path: path describing a repo. nick@key/reponame :param truster: identity whose trust list to use. + :param repo: If given, add a path that points to the resolved URI. :return: """ # Expecting <id stuff>/reponame @@ -416,7 +417,22 @@ def resolve_pull_uri(ui, path, truster): # TODO: How to handle redundancy? Does Infocalypse automatically try # an R0 if an R1 fails? - return find_repo(ui, identity, repo_name) + request_uri = find_repo(ui, identity, repo_name) + + if repo: + # TODO: Writing paths in this way preserves comments, + # but does not allow dealing intelligently with paths of the same + # name. Also it's duplicated in the clone support. + ui.status("Adding this repository as path '{0}'. To pull from the " + "same repository in the future use this path.\n" + .format(identity.nickname)) + with repo.opener("hgrc", "a", text=True) as f: + f.write(""" +[paths] +{0} = freenet:{1} +""".format(identity.nickname, request_uri)) + + return request_uri def resolve_push_uri(ui, path, resolve_edition=True):