summaryrefslogtreecommitdiff
path: root/lorrycontroller
diff options
context:
space:
mode:
authorBen Hutchings <ben.hutchings@codethink.co.uk>2020-05-14 15:52:23 +0100
committerBen Hutchings <ben.hutchings@codethink.co.uk>2020-06-01 17:16:38 +0100
commit36a0a30c13e669514ba2bce7a7f77d53f7275a11 (patch)
tree57f51f615b6ec2fbdb0e59d432a6951b8fc7f862 /lorrycontroller
parent1306be9e3ccc086153ffe0e28d2d7062f45dc157 (diff)
downloadlorry-controller-36a0a30c13e669514ba2bce7a7f77d53f7275a11.tar.gz
lsupstreams: Prefer more specific remote prefixes in prefixmap
In order to support Downstream Hosts with restricted repository hierarchies (like Gitea's 2 levels), it is useful to be able to map both a directory and a subdirectory of it from an Upstream Host that has a deeper hierarchy. Convert the prefixmap into a list of (remote, local) tuples and sort in reverse order, so that a subdirectory prefix will appear before its parent directory prefix if both are present.
Diffstat (limited to 'lorrycontroller')
-rw-r--r--lorrycontroller/lsupstreams.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/lorrycontroller/lsupstreams.py b/lorrycontroller/lsupstreams.py
index a535174..0b0802a 100644
--- a/lorrycontroller/lsupstreams.py
+++ b/lorrycontroller/lsupstreams.py
@@ -94,12 +94,13 @@ class HostRepositoryLister(object):
return repo_map
def parse_prefixmap(self, prefixmap_string):
- return json.loads(prefixmap_string)
+ # Sort prefixes in reverse order, so more specific prefixes
+ # come first
+ return sorted(json.loads(prefixmap_string).items(), reverse=True)
def map_one_remote_repo_to_local_one(self, remote_path, prefixmap):
- for remote_prefix in prefixmap:
+ for remote_prefix, local_prefix in prefixmap:
if self.path_starts_with_prefix(remote_path, remote_prefix):
- local_prefix = prefixmap[remote_prefix]
relative_path = remote_path[len(remote_prefix):]
local_path = local_prefix + relative_path
return local_path