Moving all file cleanup to IOUtils for easier debugging.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4646 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
2e0296fef9
commit
f35d1aa43f
|
|
@ -139,11 +139,11 @@ class LsfJobRunner(val function: CommandLineFunction) extends DispatchJobRunner
|
|||
* Removes all temporary files used for this LSF job.
|
||||
*/
|
||||
def removeTemporaryFiles() = {
|
||||
FileUtils.deleteQuietly(exec)
|
||||
FileUtils.deleteQuietly(preExec)
|
||||
FileUtils.deleteQuietly(postExec)
|
||||
FileUtils.deleteQuietly(jobDoneFile)
|
||||
FileUtils.deleteQuietly(jobFailFile)
|
||||
IOUtils.tryDelete(exec)
|
||||
IOUtils.tryDelete(preExec)
|
||||
IOUtils.tryDelete(postExec)
|
||||
IOUtils.tryDelete(jobDoneFile)
|
||||
IOUtils.tryDelete(jobFailFile)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import org.broadinstitute.sting.queue.{QException, QSettings}
|
|||
import collection.JavaConversions._
|
||||
import org.broadinstitute.sting.queue.function.scattergather.{Gather, SimpleTextGatherFunction}
|
||||
import org.broadinstitute.sting.queue.util.{Logging, CollectionUtils, IOUtils, ReflectionUtils}
|
||||
import org.apache.commons.io.FileUtils
|
||||
|
||||
/**
|
||||
* The base interface for all functions in Queue.
|
||||
|
|
@ -157,23 +156,18 @@ trait QFunction extends Logging {
|
|||
* Deletes the log files for this function.
|
||||
*/
|
||||
def deleteLogs() = {
|
||||
deleteOutput(jobOutputFile)
|
||||
IOUtils.tryDelete(jobOutputFile)
|
||||
if (jobErrorFile != null)
|
||||
deleteOutput(jobErrorFile)
|
||||
IOUtils.tryDelete(jobErrorFile)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the output files and all the status files for this function.
|
||||
*/
|
||||
def deleteOutputs() = {
|
||||
outputs.foreach(file => deleteOutput(file))
|
||||
doneOutputs.foreach(file => deleteOutput(file))
|
||||
failOutputs.foreach(file => deleteOutput(file))
|
||||
}
|
||||
|
||||
private def deleteOutput(file: File) = {
|
||||
if (FileUtils.deleteQuietly(file))
|
||||
logger.debug("Deleted " + file)
|
||||
outputs.foreach(file => IOUtils.tryDelete(file))
|
||||
doneOutputs.foreach(file => IOUtils.tryDelete(file))
|
||||
failOutputs.foreach(file => IOUtils.tryDelete(file))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import org.broadinstitute.sting.utils.exceptions.UserException
|
|||
/**
|
||||
* A collection of utilities for modifying java.io.
|
||||
*/
|
||||
object IOUtils {
|
||||
object IOUtils extends Logging {
|
||||
/** The current directory "." */
|
||||
val CURRENT_DIR = new File(".")
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ object IOUtils {
|
|||
|
||||
def writeContents(file: File, content: String) = FileUtils.writeStringToFile(file, content)
|
||||
|
||||
def writeTempFile(content: String, prefix: String, suffix: String = "", directory: File = null) = {
|
||||
def writeTempFile(content: String, prefix: String, suffix: String = "", directory: File = null) = {
|
||||
val tempFile = absolute(File.createTempFile(prefix, suffix, directory))
|
||||
writeContents(tempFile, content)
|
||||
tempFile
|
||||
|
|
@ -181,4 +181,18 @@ object IOUtils {
|
|||
}
|
||||
tailLines
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to delete a file. Emits a warning if the file was unable to be deleted.
|
||||
* @param file File to delete.
|
||||
* @return true if the file was deleted.
|
||||
*/
|
||||
def tryDelete(file: File) = {
|
||||
val deleted = FileUtils.deleteQuietly(file)
|
||||
if (deleted)
|
||||
logger.debug("Deleted " + file)
|
||||
else if (file.exists)
|
||||
logger.warn("Unable to delete " + file)
|
||||
deleted
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class IOUtilsUnitTest extends BaseTest {
|
|||
Assert.assertTrue(tempDir.exists)
|
||||
Assert.assertFalse(tempDir.isFile)
|
||||
Assert.assertTrue(tempDir.isDirectory)
|
||||
val deleted = tempDir.delete
|
||||
val deleted = IOUtils.tryDelete(tempDir)
|
||||
Assert.assertTrue(deleted)
|
||||
Assert.assertFalse(tempDir.exists)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue