changeset 8234:0e008317f8ed

Binary dumper should try numbering output files if a file with the same name exists
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 13 Mar 2013 18:16:46 +0100
parents 9484e7602276
children 35267b295f74
files graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java
diffstat 1 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java	Wed Mar 13 17:39:27 2013 +0100
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java	Wed Mar 13 18:16:46 2013 +0100
@@ -82,16 +82,22 @@
         if (sdf == null) {
             sdf = new SimpleDateFormat("YYYY-MM-dd-HHmm");
         }
-        String fileName = "Graphs-" + Thread.currentThread().getName() + "-" + sdf.format(new Date()) + ext;
+        String prefix = "Graphs-" + Thread.currentThread().getName() + "-" + sdf.format(new Date());
+        String num = "";
+        File file;
+        int i = 0;
+        while ((file = new File(prefix + num + ext)).exists()) {
+            num = "-" + Integer.toString(++i);
+        }
         try {
             if (GraalOptions.PrintBinaryGraphs) {
-                printer = new BinaryGraphPrinter(FileChannel.open(new File(fileName).toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW));
+                printer = new BinaryGraphPrinter(FileChannel.open(file.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW));
             } else {
-                printer = new IdealGraphPrinter(new FileOutputStream(fileName));
+                printer = new IdealGraphPrinter(new FileOutputStream(file));
             }
-            TTY.println("Dumping IGV graphs to %s", fileName);
+            TTY.println("Dumping IGV graphs to %s", file.getName());
         } catch (IOException e) {
-            TTY.println("Failed to open %s to dump IGV graphs : %s", fileName, e);
+            TTY.println("Failed to open %s to dump IGV graphs : %s", file.getName(), e);
             failuresCount++;
             printer = null;
         }