[tor-commits] [onionoo/master] Make writing summary file almost atomic using a temp file.
karsten at torproject.org
karsten at torproject.org
Wed May 1 10:24:35 UTC 2013
commit 0c84865391db75a294169174e04ca585824e3111
Author: Karsten Loesing <karsten.loesing at 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.");
More information about the tor-commits
mailing list