# HG changeset patch # User Gilles Duboscq # Date 1363195006 -3600 # Node ID 0e008317f8ede8b73fc2cc5c7c03865e5518648e # Parent 9484e7602276ccfcbfdc49937f1085161a518ab5 Binary dumper should try numbering output files if a file with the same name exists diff -r 9484e7602276 -r 0e008317f8ed graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java --- 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; }