| 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); |
|---|