Ignore:
Timestamp:
01/14/10 16:08:59 (11 years ago)
Author:
ak19
Message:

Dr Bainbridge improved some code by adding the helper method collection_is_collect_group().

Location:
main/trunk/greenstone2/runtime-src/src/colservr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/colservr/collectset.cpp

    r21415 r21453  
    251251}
    252252
     253bool collectset::collection_is_collect_group (const text_t& collect_dir)
     254{
     255  text_t is_collect_group_str = "false";
     256  text_t collect_cfg = filename_cat(collect_dir, "etc", "collect.cfg");
     257
     258  if (file_exists(collect_cfg)) {
     259    char *collect_cfgc = collect_cfg.getcstr();
     260    ifstream confin(collect_cfgc);
     261
     262    if (confin) {
     263      text_tarray cfgline;
     264
     265      while (read_cfg_line(confin, cfgline) >= 0) {
     266    if (cfgline.size() == 2) {
     267      text_t key = cfgline[0];
     268      cfgline.erase(cfgline.begin());
     269      if (key == "collectgroup") {
     270        is_collect_group_str = cfgline[0];
     271        break;
     272      }
     273    }
     274      }
     275
     276      confin.close();
     277    }
     278
     279    delete []collect_cfgc;
     280  }
     281
     282  bool is_collect_group = (is_collect_group_str == "true") ? true : false;
     283
     284  return is_collect_group;
     285}
     286
     287
    253288// add_collection sets up the collectionserver and calls
    254289// add_collectserver
     
    257292                 const text_t& collecthome)
    258293{
    259 
    260   this->remove_collection(collection);
    261  
    262294  // read config file to see if built with mg, mgpp, or lucene
    263295  text_t buildtype = "mg"; // mg is default
    264296  text_t infodbtype = "gdbm"; // gdbm is default
    265297
     298  this->remove_collection(collection);
     299 
    266300  collectserver *cserver = NULL;
    267 
    268   text_tarray cfgline;
    269   text_t key;
    270301
    271302  text_t build_cfg = filename_cat(collecthome, collection, "index", "build.cfg");
     
    275306   
    276307    if (confin) {
     308      text_tarray cfgline;
     309
    277310      while (read_cfg_line(confin, cfgline) >= 0) {
    278311    if (cfgline.size() == 2) {
    279       key = cfgline[0];
     312      text_t key = cfgline[0];
    280313      cfgline.erase(cfgline.begin());
    281314      if (key == "buildtype") {
     
    407440  else {
    408441    // see if it is a collectgroup col
    409 
    410 
    411     // This routine essentially exists twice in the code now (see add_collection_group)
    412     // factor out as support routine
    413 
    414     text_t collect_cfg = filename_cat(collecthome, collection, "etc", "collect.cfg");
    415     if (file_exists (collect_cfg)) {
    416       char *collect_cfgc = collect_cfg.getcstr();
    417       ifstream confin(collect_cfgc);     
    418 
    419       text_t is_collect_group = "false";
    420 
    421       if (confin) {
    422     while (read_cfg_line(confin, cfgline) >= 0) {
    423       if (cfgline.size() == 2) {
    424         key = cfgline[0];
    425        
    426         cfgline.erase(cfgline.begin());
    427         if (key == "collectgroup") {
    428           is_collect_group = cfgline[0];
    429         }
    430       }
    431     }
    432     confin.close();
    433       }
    434       delete []collect_cfgc;
    435      
    436       if (is_collect_group != "true") {
    437     // an unbuilt leaf collection
    438     return;
    439       }
    440 
    441       // by this point we know we will need a cserver
    442       cserver = new collectserver();
    443 
    444     }
    445     else {
    446       // no collect.cfg => filter it out from list of collections added
    447       return;
    448     }
    449   }
    450 
    451   // inform collection server and everything it contains about its
    452   // collection name
    453   cserver->configure ("collection", collection);
    454   cserver->configure ("gsdlhome", gsdlhome);
    455   cserver->configure ("collecthome", collecthome);
    456   cservers.addcollectserver (cserver);
     442    text_t this_collect_dir = filename_cat(collecthome, collection);
     443    if (collection_is_collect_group(this_collect_dir)) {
     444    // by this point we know we will need a cserver
     445    cserver = new collectserver();
     446    }
     447    // else not a collect group, or there was no collect.cfg
     448    // => leave cserver as NULL so it will not be added into cservers
     449  }
     450
     451  if (cserver != NULL) {
     452    // inform collection server and everything it contains about its
     453    // collection name
     454    cserver->configure ("collection", collection);
     455    cserver->configure ("gsdlhome", gsdlhome);
     456    cserver->configure ("collecthome", collecthome);
     457    cservers.addcollectserver (cserver);
     458  }
    457459}
    458460
     
    488490
    489491  // need to read collect.cfg for 'collectgroup' as class hasn't been initialised through 'init' yet
    490   text_t is_collect_group;
    491   text_tarray cfgline;
    492   text_t key;
    493   text_t collect_cfg = filename_cat(collect_group_dir, "etc", "collect.cfg");
    494   char *collect_cfgc = collect_cfg.getcstr();
    495   ifstream confin(collect_cfgc);
    496 
    497   if (confin) {
    498     while (read_cfg_line(confin, cfgline) >= 0) {
    499       if (cfgline.size() == 2) {
    500     key = cfgline[0];
    501     cfgline.erase(cfgline.begin());
    502     if (key == "collectgroup") {
    503       is_collect_group = cfgline[0];
    504       break;
    505     }
    506       }
    507     }
    508     confin.close();
    509   }
    510   delete []collect_cfgc;
    511 
    512   if (is_collect_group == "true") {
     492  if (collection_is_collect_group(collect_group_dir)) {
    513493    if (read_dir (collect_group_dir, group)) {
    514494     
  • main/trunk/greenstone2/runtime-src/src/colservr/collectset.h

    r21324 r21453  
    8787      return cservers.getcollectserver(collection);
    8888    }
     89
     90 protected:
     91  bool collection_is_collect_group (const text_t& collect_dir);
    8992};
    9093
Note: See TracChangeset for help on using the changeset viewer.