commit 0c84865391db75a294169174e04ca585824e3111 Author: Karsten Loesing karsten.loesing@gmx.net Date: Wed May 1 11:46:32 2013 +0200
Make writing summary file almost atomic using a temp file. --- src/org/torproject/onionoo/CurrentNodes.java | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/src/org/torproject/onionoo/CurrentNodes.java b/src/org/torproject/onionoo/CurrentNodes.java index 4319836..32d6576 100644 --- a/src/org/torproject/onionoo/CurrentNodes.java +++ b/src/org/torproject/onionoo/CurrentNodes.java @@ -174,8 +174,10 @@ public class CurrentNodes { boolean includeOldNodes) { try { summaryFile.getParentFile().mkdirs(); + File summaryTempFile = new File( + summaryFile.getAbsolutePath() + ".tmp"); BufferedWriter bw = new BufferedWriter(new FileWriter( - summaryFile)); + summaryTempFile)); SimpleDateFormat dateTimeFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC")); @@ -265,6 +267,8 @@ public class CurrentNodes { + "null\n"); } bw.close(); + summaryFile.delete(); + summaryTempFile.renameTo(summaryFile); } catch (IOException e) { System.err.println("Could not write '" + summaryFile.getAbsolutePath() + "' to disk. Exiting.");