From 36a0a30c13e669514ba2bce7a7f77d53f7275a11 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Thu, 14 May 2020 15:52:23 +0100 Subject: 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. --- lorrycontroller/lsupstreams.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lorrycontroller') 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 -- cgit v1.2.1