ProjectRepairer: Refactor copy() to take a destination dir buildCopyDestination() appends objects/pack/ to the remote path itself, so copy() can only ever populate a destination's pack directory. Pass the remote subdirectory in instead, with the pack callers naming PACK_DIR. The rsync commands produced are unchanged. Change-Id: I7bf05966dd95b7827864f2ae5a0a39fe9ca050eb
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ProjectRepairer.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ProjectRepairer.java index b9b8f82..89ac793 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/ProjectRepairer.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ProjectRepairer.java
@@ -36,6 +36,8 @@ @Singleton public class ProjectRepairer { + private static final String PACK_DIR = "objects/pack/"; + private final GitRepositoryManager gitManager; private final ReplicationConfig replicationConfig; @@ -87,11 +89,11 @@ private boolean copyInOrder(Path packDir, URIish uri, OutputStream out) throws InterruptedIOException { - return copy(packDir, uri, out, "*.pack") == 0 - && copy(packDir, uri, out, "*.idx", "*.bitmap", "*.rev") == 0; + return copy(packDir, uri, out, PACK_DIR, "*.pack") == 0 + && copy(packDir, uri, out, PACK_DIR, "*.idx", "*.bitmap", "*.rev") == 0; } - private int copy(Path src, URIish uri, OutputStream out, String... includes) + private int copy(Path src, URIish uri, OutputStream out, String destDir, String... includes) throws InterruptedIOException { List<String> cmd = new ArrayList<>(); cmd.add(replicationConfig.getRsyncPath()); @@ -104,7 +106,7 @@ } cmd.add("--exclude=*"); cmd.add(src.toAbsolutePath().normalize() + "/"); - cmd.add(buildCopyDestination(uri)); + cmd.add(buildCopyDestination(uri, destDir)); repLog.atInfo().log("Running repair cmd: %s", String.join(" ", cmd)); @@ -119,7 +121,7 @@ } StreamCopyThread outStream = new StreamCopyThread(p.getInputStream(), out); - outStream.setName("copy-packs-output"); + outStream.setName("repair-copy-output"); outStream.start(); try { int code = p.waitFor(); @@ -140,15 +142,15 @@ } } - private static String buildCopyDestination(URIish uri) { + private static String buildCopyDestination(URIish uri, String destDir) { String host = uri.getHost(); String path = uri.getPath(); - String remotePackPath = QuotedString.BOURNE.quote(path + "/objects/pack/"); + String remotePath = QuotedString.BOURNE.quote(path + "/" + destDir); String user = uri.getUser(); if (user != null && !user.isEmpty()) { - return user + "@" + host + ":" + remotePackPath; + return user + "@" + host + ":" + remotePath; } - return host + ":" + remotePackPath; + return host + ":" + remotePath; } private static String buildSshTransport(URIish uri) {