From 5d8790eb85220b082ea5b288be51392c2613ecdc Mon Sep 17 00:00:00 2001
From: Yonik Seeley <yonik@apache.org>
Date: Sat, 29 Jan 2011 02:24:53 +0000
Subject: [PATCH] SOLR-1983 SOLR-2156: set replication flags and cleanup

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1064942 13f79535-47bb-0310-9956-ffa450edef68
---
 solr/CHANGES.txt                                      | 5 +++++
 solr/src/java/org/apache/solr/handler/SnapPuller.java | 9 ++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 815b140524b..5022a1ed447 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -653,6 +653,11 @@ Bug Fixes
 * SOLR-2261: fix velocity template layout.vm that referred to an older
   version of jquery.  (Eric Pugh via rmuir)
 
+* SOLR-1983: snappuller fails when modifiedConfFiles is not empty and
+  full copy of index is needed. (Alexander Kanarsky via yonik)
+
+* SOLR-2156: SnapPuller fails to clean Old Index Directories on Full Copy
+  (Jayendra Patil via yonik)
 
 Other Changes
 ----------------------
diff --git a/solr/src/java/org/apache/solr/handler/SnapPuller.java b/solr/src/java/org/apache/solr/handler/SnapPuller.java
index 88ac16671cf..b93d34f389b 100644
--- a/solr/src/java/org/apache/solr/handler/SnapPuller.java
+++ b/solr/src/java/org/apache/solr/handler/SnapPuller.java
@@ -300,15 +300,17 @@ public class SnapPuller {
         isFullCopyNeeded = true;
       successfulInstall = false;
       boolean deleteTmpIdxDir = true;
+      File indexDir = null ;
       try {
-        File indexDir = new File(core.getIndexDir());
+        indexDir = new File(core.getIndexDir());
         downloadIndexFiles(isFullCopyNeeded, tmpIndexDir, latestVersion);
         LOG.info("Total time taken for download : " + ((System.currentTimeMillis() - replicationStartTime) / 1000) + " secs");
         Collection<Map<String, Object>> modifiedConfFiles = getModifiedConfFiles(confFilesToDownload);
         if (!modifiedConfFiles.isEmpty()) {
           downloadConfFiles(confFilesToDownload, latestVersion);
           if (isFullCopyNeeded) {
-            modifyIndexProps(tmpIndexDir.getName());
+            successfulInstall = modifyIndexProps(tmpIndexDir.getName());
+            deleteTmpIdxDir =  false;
           } else {
             successfulInstall = copyIndexFiles(tmpIndexDir, indexDir);
           }
@@ -339,7 +341,8 @@ public class SnapPuller {
       } catch (Exception e) {
         throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Index fetch failed : ", e);
       } finally {
-        if(deleteTmpIdxDir) delTree(tmpIndexDir);
+        if (deleteTmpIdxDir) delTree(tmpIndexDir);
+        else delTree(indexDir);
       }
       return successfulInstall;
     } finally {