Index: main/trunk/greenstone2/runtime-src/src/colservr/collectset.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/colservr/collectset.cpp	(revision 21435)
+++ main/trunk/greenstone2/runtime-src/src/colservr/collectset.cpp	(revision 21453)
@@ -251,4 +251,39 @@
 }
 
+bool collectset::collection_is_collect_group (const text_t& collect_dir)
+{
+  text_t is_collect_group_str = "false";
+  text_t collect_cfg = filename_cat(collect_dir, "etc", "collect.cfg");
+
+  if (file_exists(collect_cfg)) {
+    char *collect_cfgc = collect_cfg.getcstr();
+    ifstream confin(collect_cfgc);
+
+    if (confin) {
+      text_tarray cfgline;
+
+      while (read_cfg_line(confin, cfgline) >= 0) {
+	if (cfgline.size() == 2) {
+	  text_t key = cfgline[0];
+	  cfgline.erase(cfgline.begin());
+	  if (key == "collectgroup") {
+	    is_collect_group_str = cfgline[0];
+	    break;
+	  }
+	}
+      }
+
+      confin.close();
+    }
+
+    delete []collect_cfgc;
+  }
+
+  bool is_collect_group = (is_collect_group_str == "true") ? true : false;
+
+  return is_collect_group;
+}
+
+
 // add_collection sets up the collectionserver and calls
 // add_collectserver
@@ -257,15 +292,11 @@
 				 const text_t& collecthome) 
 {
-
-  this->remove_collection(collection);
-  
   // read config file to see if built with mg, mgpp, or lucene
   text_t buildtype = "mg"; // mg is default
   text_t infodbtype = "gdbm"; // gdbm is default
 
+  this->remove_collection(collection);
+  
   collectserver *cserver = NULL;
-
-  text_tarray cfgline;
-  text_t key;
 
   text_t build_cfg = filename_cat(collecthome, collection, "index", "build.cfg");
@@ -275,7 +306,9 @@
     
     if (confin) {
+      text_tarray cfgline;
+
       while (read_cfg_line(confin, cfgline) >= 0) {
 	if (cfgline.size() == 2) {
-	  key = cfgline[0];
+	  text_t key = cfgline[0];
 	  cfgline.erase(cfgline.begin());
 	  if (key == "buildtype") {
@@ -407,52 +440,21 @@
   else {
     // see if it is a collectgroup col
-
-
-    // This routine essentially exists twice in the code now (see add_collection_group)
-    // factor out as support routine
-
-    text_t collect_cfg = filename_cat(collecthome, collection, "etc", "collect.cfg");
-    if (file_exists (collect_cfg)) {
-      char *collect_cfgc = collect_cfg.getcstr();
-      ifstream confin(collect_cfgc);     
-
-      text_t is_collect_group = "false";
-
-      if (confin) {
-	while (read_cfg_line(confin, cfgline) >= 0) {
-	  if (cfgline.size() == 2) {
-	    key = cfgline[0];
-	    
-	    cfgline.erase(cfgline.begin());
-	    if (key == "collectgroup") {
-	      is_collect_group = cfgline[0];
-	    }
-	  }
-	}
-	confin.close();
-      }
-      delete []collect_cfgc;
-      
-      if (is_collect_group != "true") {
-	// an unbuilt leaf collection
-	return;
-      }
-
-      // by this point we know we will need a cserver
-      cserver = new collectserver();
-
-    }
-    else {
-      // no collect.cfg => filter it out from list of collections added
-      return;
-    }
-  }
-
-  // inform collection server and everything it contains about its
-  // collection name
-  cserver->configure ("collection", collection);
-  cserver->configure ("gsdlhome", gsdlhome);
-  cserver->configure ("collecthome", collecthome); 
-  cservers.addcollectserver (cserver);
+    text_t this_collect_dir = filename_cat(collecthome, collection);
+    if (collection_is_collect_group(this_collect_dir)) {
+	// by this point we know we will need a cserver
+	cserver = new collectserver();
+    }
+    // else not a collect group, or there was no collect.cfg 
+    // => leave cserver as NULL so it will not be added into cservers
+  }
+
+  if (cserver != NULL) {
+    // inform collection server and everything it contains about its
+    // collection name
+    cserver->configure ("collection", collection);
+    cserver->configure ("gsdlhome", gsdlhome);
+    cserver->configure ("collecthome", collecthome); 
+    cservers.addcollectserver (cserver);
+  }
 }
 
@@ -488,27 +490,5 @@
 
   // need to read collect.cfg for 'collectgroup' as class hasn't been initialised through 'init' yet
-  text_t is_collect_group;
-  text_tarray cfgline;
-  text_t key;
-  text_t collect_cfg = filename_cat(collect_group_dir, "etc", "collect.cfg");
-  char *collect_cfgc = collect_cfg.getcstr();
-  ifstream confin(collect_cfgc);
-
-  if (confin) {
-    while (read_cfg_line(confin, cfgline) >= 0) {
-      if (cfgline.size() == 2) {
-	key = cfgline[0];
-	cfgline.erase(cfgline.begin());
-	if (key == "collectgroup") {
-	  is_collect_group = cfgline[0];
-	  break;
-	}
-      }
-    }
-    confin.close();
-  }
-  delete []collect_cfgc;
-
-  if (is_collect_group == "true") {
+  if (collection_is_collect_group(collect_group_dir)) {
     if (read_dir (collect_group_dir, group)) {
       
Index: main/trunk/greenstone2/runtime-src/src/colservr/collectset.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/colservr/collectset.h	(revision 21435)
+++ main/trunk/greenstone2/runtime-src/src/colservr/collectset.h	(revision 21453)
@@ -87,4 +87,7 @@
       return cservers.getcollectserver(collection);
     }
+
+ protected:
+  bool collection_is_collect_group (const text_t& collect_dir);
 };
 
