Changeset 16895

Show
Ignore:
Timestamp:
19.08.2008 14:13:44 (11 years ago)
Author:
davidb
Message:

Runtime code can now support GDBM database being provided as a gzipped txt file, which is platform independant. If the required .ldb (or .bdb) isn't there than the runtime system executes txt2db to generate it. The rest of the code then works as before

Location:
gsdl/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/common-src/src/lib/gdbmclass.cpp

    r15679 r16895  
    2727#include "gsdltools.h" 
    2828#include "gsdlunicode.h" 
     29#include "fileutil.h" 
     30 
     31 
    2932 
    3033 
     
    4447                  ) 
    4548{ 
     49 
    4650  text_t data_location; 
    4751  int block_size = 512; 
     
    6367  { 
    6468    gdbm_mode = GDBM_WRCREAT; 
     69  } 
     70 
     71  if (gdbm_mode == GDBM_READER) { 
     72    // Looking to read in the database 
     73    // => check to see if .ldb/.bdb file already there 
     74    // if not (first time) then generate using txt2db 
     75    if (!file_exists(filename)) { 
     76 
     77      // need to generate architecture native GDBM file using txt2db 
     78 
     79      // replace sought after gdbm filename ext with ".txt.gz" 
     80 
     81      text_t::const_iterator begin = filename.begin(); 
     82      text_t::const_iterator end= filename.end(); 
     83      text_t::const_iterator here = end; 
     84 
     85      bool found_ext = false; 
     86 
     87      while (here != begin) { 
     88    if (*here == '.') { 
     89      found_ext = true; 
     90      break; 
     91    } 
     92    here--; 
     93      } 
     94       
     95      text_t filename_root; 
     96 
     97      if (found_ext) { 
     98    filename_root = substr(begin,here); 
     99      } 
     100      else { 
     101    filename_root = filename; 
     102      } 
     103 
     104      text_t txtgz_filename = filename_root + ".txt.gz"; 
     105 
     106      text_t cmd = "gzip --decompress --to-stdout \"" + txtgz_filename + "\""; 
     107      cmd += " | txt2db \"" + filename + "\""; 
     108 
     109      int rv = gsdl_system(cmd, true, cerr); 
     110      if (rv != 0) { 
     111    cerr << "Tried to run command \""<<cmd<<"\", but it failed\n"; 
     112      } 
     113    } 
    65114  } 
    66115 
  • gsdl/trunk/common-src/src/lib/gsdltools.cpp

    r9593 r16895  
    2525 
    2626#include "gsdltools.h" 
     27#include "fileutil.h" 
    2728 
    2829#if defined(__WIN32__) 
     
    3031#include <process.h> 
    3132#endif 
     33 
     34#if !defined (__WIN32__) 
     35#include <sys/utsname.h> 
     36#include <unistd.h> 
     37#endif 
     38 
    3239 
    3340bool littleEndian() { 
     
    160167} 
    161168 
     169 
     170static bool gsdl_setenv_done = false; 
     171 
     172bool set_gsdl_env_vars (const text_t& gsdlhome)  
     173{ 
     174  if (gsdl_setenv_done) { return true; } 
     175 
     176  // set up GSDLOS, GSDLHOME and PATH environment variables 
     177 
     178  text_t gsdlos, path; 
     179  unsigned int path_separator = ':'; 
     180 
     181#if defined (__WIN32__) 
     182  gsdlos = "windows"; 
     183  path_separator = ';'; 
     184 
     185  path = filename_cat (gsdlhome, "bin", "windows", "perl", "bin;"); 
     186 
     187#else 
     188  struct utsname *buf = new struct utsname(); 
     189  int i = uname (buf); 
     190  if (i == -1) gsdlos = "linux"; // uname failed, default to linux 
     191  else gsdlos.setcstr (buf->sysname); 
     192  delete buf; 
     193  lc (gsdlos); 
     194#endif 
     195 
     196  // according to getenv documentation (after a bit of digging), *getenv* 
     197  // is responsible for the char* pointer returned, so no need for us 
     198  // to free it (in fact that would be a mistake!) 
     199 
     200  char* orig_pathc = getenv ("PATH");  
     201  path += filename_cat (gsdlhome, "bin", gsdlos); 
     202  path.push_back (path_separator); 
     203  path += filename_cat (gsdlhome, "bin", "script"); 
     204  if (orig_pathc != NULL) { 
     205    path.push_back (path_separator); 
     206    path += orig_pathc; 
     207  }   
     208 
     209  // these will be cleaned up in the destructor 
     210  char* gsdlosc = gsdlos.getcstr(); 
     211  char* gsdlhomec = gsdlhome.getcstr(); 
     212  char* pathc = path.getcstr(); 
     213   
     214  if ((setenv("GSDLOS",gsdlosc,1)!=0)  
     215      || (setenv("GSDLHOME",gsdlhomec,1)!=0)  
     216      || (setenv("PATH",pathc,1)!=0)) 
     217    { 
     218      perror("Setting Greenstone environment variables"); 
     219      return false; 
     220    } 
     221 
     222  delete [] gsdlosc; 
     223  delete [] gsdlhomec; 
     224  delete [] pathc; 
     225 
     226  gsdl_setenv_done = true; 
     227 
     228  return true; 
     229} 
     230 
     231 
     232 
    162233// attempts to work out if perl is functional 
    163234bool perl_ok (ostream &logout) { 
  • gsdl/trunk/common-src/src/lib/gsdltools.h

    r8727 r16895  
    6565int gsdl_system (const text_t &cmd, bool sync, ostream &logout); 
    6666 
     67bool set_gsdl_env_vars (const text_t& gsdlhome) ; 
     68 
    6769// attempts to work out if perl is functional 
    6870bool perl_ok (ostream &logout); 
  • gsdl/trunk/runtime-src/src/colservr/collectset.cpp

    r16312 r16895  
    3030#include "gsdlsitecfg.h" 
    3131#include "gdbmclass.h" 
     32#include "gsdltools.h" 
    3233#include "fileutil.h" 
    3334#include "filter.h" 
     
    8182    } 
    8283  } 
     84 
     85  set_gsdl_env_vars(gsdlhome); 
    8386} 
    8487