diff --git a/snapshot-service-impl/src/main/java/org/duracloud/snapshot/service/impl/RestoreManagerImpl.java b/snapshot-service-impl/src/main/java/org/duracloud/snapshot/service/impl/RestoreManagerImpl.java index 74bed5d..bf1b101 100644 --- a/snapshot-service-impl/src/main/java/org/duracloud/snapshot/service/impl/RestoreManagerImpl.java +++ b/snapshot-service-impl/src/main/java/org/duracloud/snapshot/service/impl/RestoreManagerImpl.java @@ -489,20 +489,19 @@ public void finalizeRestores() { try { String spaceId = destination.getSpaceId(); boolean spaceExists = store.spaceExists(spaceId); - boolean spaceEmpty = false; - - if(spaceExists) { + + if (spaceExists) { Iterator it = store.getSpaceContents(spaceId); - spaceEmpty = !it.hasNext(); - if (spaceEmpty) { // if space is empty + if (!it.hasNext()) { // if space is empty // Call DuraCloud to remove space log.info("Deleting expired restoration space: " + spaceId + " at host: " + destination.getHost()); store.deleteSpace(spaceId); + spaceExists = false; } } - if (!spaceExists || spaceEmpty){ + if (!spaceExists) { // Update restore status validateAndSet(restoration, RestoreStatus.RESTORATION_EXPIRED, @@ -522,8 +521,6 @@ public void finalizeRestores() { log.info("Space {} is not empty. Space will be removed and restoration {} transition to " + "expired state when space is empty.", spaceId, restoration); } - - } catch (Exception e) { log.error("Failed to transition restore " + restoration.getRestorationId() + diff --git a/snapshot-service-impl/src/test/java/org/duracloud/snapshot/service/impl/RestoreManagerImplTest.java b/snapshot-service-impl/src/test/java/org/duracloud/snapshot/service/impl/RestoreManagerImplTest.java index 58fe74e..1cabd39 100644 --- a/snapshot-service-impl/src/test/java/org/duracloud/snapshot/service/impl/RestoreManagerImplTest.java +++ b/snapshot-service-impl/src/test/java/org/duracloud/snapshot/service/impl/RestoreManagerImplTest.java @@ -308,6 +308,7 @@ public void testFinalizeRestores() throws Exception { expect(destination.getSpaceId()).andReturn(spaceId); expect(destination.getHost()).andReturn(host); + expect(contentStore.spaceExists(spaceId)).andReturn(true); expect(contentStore.getSpaceContents(spaceId)) .andReturn(Collections.emptyList().iterator());