From 7c25cd575572410ef90a53d1af853fde7d011bf8 Mon Sep 17 00:00:00 2001 From: Doug Kelly Date: Fri, 3 Oct 2014 15:13:11 -0500 Subject: Prevent creating repos on extra servers If using a group to replicate only certain repositories, it is possible to be in a state where the authGroup is used on some servers but not others. If this happened, Gerrit would create the repository on all servers, even if the authGroup would prevent replicating code to it. By ensuring the authGroup can see the project first, we don't create the repository if it's not needed. Bug: Issue 543 Change-Id: I2f189bdb6007228d0b25a6ce9c0357b3f97e4ced --- .../gerrit/plugins/replication/Destination.java | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java index 20b0a3f..feff6c0 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java @@ -200,25 +200,29 @@ class Destination { return cfg.getInt("remote", rc.getName(), name, defValue); } - void schedule(final Project.NameKey project, final String ref, - final URIish uri, ReplicationState state) { + private boolean isVisible(final Project.NameKey project, + ReplicationState... states) { try { - boolean visible = threadScoper.scope(new Callable(){ + return threadScoper.scope(new Callable() { @Override public Boolean call() throws NoSuchProjectException { return controlFor(project).isVisible(); } }).call(); - if (!visible) { - return; - } } catch (NoSuchProjectException err) { - stateLog.error(String.format( - "source project %s not available", project), err, state); - return; + stateLog.error(String.format("source project %s not available", project), + err, states); } catch (Exception e) { throw Throwables.propagate(e); } + return false; + } + + void schedule(final Project.NameKey project, final String ref, + final URIish uri, ReplicationState state) { + if (!isVisible(project, state)) { + return; + } if (!replicatePermissions) { PushOne e; @@ -380,7 +384,11 @@ class Destination { } } - boolean wouldPushProject(Project.NameKey project) { + boolean wouldPushProject(final Project.NameKey project) { + if (!isVisible(project)) { + return false; + } + // by default push all projects if (projects.length < 1) { return true; -- cgit v1.2.3