Commit e74cdf5b authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Improved error handeling on executable check

parent 894af898
...@@ -99,37 +99,38 @@ trait BiopetCommandLineFunction extends CommandLineResources { biopetFunction => ...@@ -99,37 +99,38 @@ trait BiopetCommandLineFunction extends CommandLineResources { biopetFunction =>
*/ */
protected[core] def preProcessExecutable() { protected[core] def preProcessExecutable() {
if (!BiopetCommandLineFunction.executableMd5Cache.contains(executable)) { if (!BiopetCommandLineFunction.executableMd5Cache.contains(executable)) {
try if (executable != null) { if (executable != null) {
if (!BiopetCommandLineFunction.executableCache.contains(executable)) { if (!BiopetCommandLineFunction.executableCache.contains(executable)) {
val oldExecutable = executable try {
val buffer = new StringBuffer() val oldExecutable = executable
val cmd = Seq("which", executable) val buffer = new StringBuffer()
val process = Process(cmd).run(ProcessLogger(buffer.append(_))) val cmd = Seq("which", executable)
if (process.exitValue == 0) { val process = Process(cmd).run(ProcessLogger(buffer.append(_)))
executable = buffer.toString if (process.exitValue == 0) {
val file = new File(executable) executable = buffer.toString
if (executableToCanonicalPath) executable = file.getCanonicalPath val file = new File(executable)
else executable = file.getAbsolutePath if (executableToCanonicalPath) executable = file.getCanonicalPath
} else { else executable = file.getAbsolutePath
Logging.addError("executable: '" + executable + "' not found, please check config") } else Logging.addError("executable: '" + executable + "' not found, please check config")
BiopetCommandLineFunction.executableCache += oldExecutable -> executable
BiopetCommandLineFunction.executableCache += executable -> executable
} catch {
case ioe: java.io.IOException =>
logger.warn(s"Could not use 'which' on '$executable', check on executable skipped: " + ioe)
} }
BiopetCommandLineFunction.executableCache += oldExecutable -> executable } else executable = BiopetCommandLineFunction.executableCache(executable)
BiopetCommandLineFunction.executableCache += executable -> executable
} else {
executable = BiopetCommandLineFunction.executableCache(executable)
}
if (!BiopetCommandLineFunction.executableMd5Cache.contains(executable)) { if (!BiopetCommandLineFunction.executableMd5Cache.contains(executable)) {
val is = new FileInputStream(executable) if (new File(executable).exists()) {
val cnt = is.available val is = new FileInputStream(executable)
val bytes = Array.ofDim[Byte](cnt) val cnt = is.available
is.read(bytes) val bytes = Array.ofDim[Byte](cnt)
is.close() is.read(bytes)
val temp = MessageDigest.getInstance("MD5").digest(bytes).map("%02X".format(_)).mkString.toLowerCase is.close()
BiopetCommandLineFunction.executableMd5Cache += executable -> temp val temp = MessageDigest.getInstance("MD5").digest(bytes).map("%02X".format(_)).mkString.toLowerCase
BiopetCommandLineFunction.executableMd5Cache += executable -> temp
} else BiopetCommandLineFunction.executableMd5Cache += executable -> "file_does_not_exist"
} }
} catch {
case ioe: java.io.IOException => logger.warn("Could not use 'which', check on executable skipped: " + ioe)
} }
} }
val md5 = BiopetCommandLineFunction.executableMd5Cache.get(executable) val md5 = BiopetCommandLineFunction.executableMd5Cache.get(executable)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment