changeset 424:b3e2a41e71ba

7902354: jcstress should remove jcstress*stdout/stderr files
author shade
date Wed, 16 Jan 2019 15:36:45 +0100
parents ce04374d7cb9
children 5ebd6a5fe110
files jcstress-core/src/main/java/org/openjdk/jcstress/TestExecutor.java jcstress-core/src/main/java/org/openjdk/jcstress/util/FileUtils.java
diffstat 2 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/TestExecutor.java	Tue Nov 27 15:22:21 2018 +0100
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/TestExecutor.java	Wed Jan 16 15:36:45 2019 +0100
@@ -206,6 +206,10 @@
             try {
                 this.stdout = File.createTempFile("jcstress", "stdout");
                 this.stderr = File.createTempFile("jcstress", "stderr");
+
+                // Register these files for removal in case we terminate through the uncommon path
+                this.stdout.deleteOnExit();
+                this.stderr.deleteOnExit();
             } catch (IOException e) {
                 throw new IllegalStateException(e);
             }
@@ -261,18 +265,14 @@
                         } catch (IOException e) {
                             output.add("Failed to read stderr: " + e.getMessage());
                         }
-
-                        if (stdout.delete()) {
-                            output.add("Failed to delete stdout log: " + stdout);
-                        }
-                        if (stderr.delete()) {
-                            output.add("Failed to delete stderr log: " + stderr);
-                        }
-
                         throw new ForkFailedException(output);
                     }
                 } catch (InterruptedException ex) {
                     throw new ForkFailedException(ex.getMessage());
+                } finally {
+                    // The process is definitely dead, remove the temporary files.
+                    stdout.delete();
+                    stderr.delete();
                 }
                 return true;
             }
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/util/FileUtils.java	Tue Nov 27 15:22:21 2018 +0100
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/util/FileUtils.java	Wed Jan 16 15:36:45 2019 +0100
@@ -65,6 +65,7 @@
                 throw new IOException("Resource not found: " + cpLocation);
             }
             File file = File.createTempFile(prefix, suffix);
+            file.deleteOnExit();
             os = new FileOutputStream(file);
             transferTo(is, os);
             return file.getAbsolutePath();