Changeset 17907 for greenstone3/trunk/src/java/org/greenstone/gsdl3/util
- Timestamp:
- 2008-11-24T15:43:01+13:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
greenstone3/trunk/src/java/org/greenstone/gsdl3/util/GDBMWrapper.java
r16869 r17907 26 26 27 27 import java.io.UnsupportedEncodingException; 28 import java.io.File; 28 29 29 30 /** java wrapper class for gdbm - uses Java-GDBM written by Martin Pool … … 42 43 NEWDB - read/write access, db should be replaced if exists 43 44 */ 44 45 45 46 46 47 protected GdbmFile db_=null; 47 48 48 49 /** open the database filename, with mode mode - uses the constants 49 50 above, eg GdbmFile.WRITER */ … … 58 59 mode = GdbmFile.READER; 59 60 } 60 61 61 try { 62 if (db_!=null) { 63 db_.close(); 64 } 65 db_ = new GdbmFile(filename, mode); 62 if (db_!=null) { 63 db_.close(); 64 } 65 66 // The java version of the C++ code in common-src/src/lib/gdbmclass.cpp 67 if(mode == GdbmFile.READER) { 68 // Looking to read in the database 69 // => check to see if .ldb/.bdb file already there 70 // if not (first time) then generate using txt2db 71 if (!new File(filename).exists()) { 72 logger.warn("Database file " + filename + " does not exist. Looking for txtgz version of db file."); 73 74 // need to generate architecture native GDBM file using txt2db 75 76 // replace sought after gdbm filename ext with ".txt.gz" 77 78 int extension = filename.lastIndexOf('.'); 79 String txtgzFilename = filename.substring(0, extension) + ".txt.gz"; 80 if(new File(txtgzFilename).exists()) { 81 // Test to make sure Perl is on the path 82 // On Linux, the output of the test goes to STDOUT so redirect it to STDERR 83 String cmdTest = "perl -v 2>&1"; 84 //String cmdTest = "echo %PATH%"; 85 int returnValue = Processing.runProcess(cmdTest); 86 if (returnValue != 0) { 87 logger.error("Tried to find Perl. Return exit value of running " 88 + cmdTest + ": " + returnValue + ", (expected this to be 0)"); 89 logger.error("Check that Perl is set in your PATH environment variable."); 90 //log.error("At present, PATH=" + System.getenv("PATH")); 91 } 92 93 String cmd = "perl -S txtgz-to-gdbm.pl \"" + txtgzFilename + "\" \"" + filename + "\""; 94 returnValue = Processing.runProcess(cmd); 95 // For some reason, launching this command with gsdl_system() still returns 1 96 // even when it returns 0 when run from the command-line. We can check whether 97 // we succeeded by looking at whether the output database file was created. 98 if (returnValue != 0) { 99 logger.warn("Warning, non-zero return value on running command \"" + cmd + "\": " + returnValue); 100 if (!new File(filename).exists()) { 101 logger.error("Tried to run command \"" + cmd + "\", but it failed"); 102 } 103 } 104 } 105 } 106 } 107 108 db_ = new GdbmFile(filename, mode); 66 109 } catch ( GdbmException e) { // the database wasn't opened or created 67 68 110 logger.error("couldn't open database "+filename); 111 return false; 69 112 } 70 113 db_.setKeyPacking(new StringPacking());
Note:
See TracChangeset
for help on using the changeset viewer.