From c2bab2c122aac19ecec78d631291526e42af0e93 Mon Sep 17 00:00:00 2001 From: Lex Spoon Date: Tue, 24 Jul 2007 15:22:30 +0000 Subject: delay the deletion of compiled files until the JVM is ready to exit (bug #1218) --- src/compiler/scala/tools/nsc/ScriptRunner.scala | 37 ++++++++++++------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala index cceed5b5c9..3266ec3799 100644 --- a/src/compiler/scala/tools/nsc/ScriptRunner.scala +++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala @@ -284,6 +284,10 @@ class ScriptRunner { compiledPath.delete // the file is created as a file; make it a directory compiledPath.mkdirs + // delete the directory after the user code has finished + Runtime.getRuntime.addShutdownHook(new Thread { + override def run { deleteRecursively(compiledPath) }}) + settings.outdir.value = compiledPath.getPath if (settings.nocompdaemon.value) { @@ -316,31 +320,24 @@ class ScriptRunner { // The pre-compiled jar is old. Recompile the script. jarFile.delete val (compiledPath, compok) = compile - try { - if (compok) { - tryMakeJar(jarFile, compiledPath) - if (jarOK) { - deleteRecursively(compiledPath) - handler(jarFile.getAbsolutePath) - } else { - // run from the interpreter's temporary - // directory - handler(compiledPath.getPath) - } + + if (compok) { + tryMakeJar(jarFile, compiledPath) + if (jarOK) { + deleteRecursively(compiledPath) // may as well do it now + handler(jarFile.getAbsolutePath) + } else { + // jar failed; run directly from the class files + handler(compiledPath.getPath) } - } finally { - deleteRecursively(compiledPath) } } } else { - // don't use the cache; just run from the interpreter's temporary directory + // don't use a cache jar at all--just use the class files val (compiledPath, compok) = compile - try { - if (compok) - handler(compiledPath.getPath) - } finally { - deleteRecursively(compiledPath) - } + + if (compok) + handler(compiledPath.getPath) } } -- cgit v1.2.3