Skip to content

Commit

Permalink
Safer writing of the meta.json file. issue #106
Browse files Browse the repository at this point in the history
  • Loading branch information
itaiag committed Sep 29, 2016
1 parent 91476f6 commit d6b19e0
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package il.co.topq.report.business.execution;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Map;

import org.slf4j.Logger;
Expand Down Expand Up @@ -52,7 +55,13 @@ protected void writeToPersistency() {
}
}
try {
new ObjectMapper().writeValue(getExecutionMetaFile(), getExecutionsCache());
// We will create a temporary file and only after successful
// write we
// will move it to be the actual file.
final File executionTempMetaFile = new File(executionMetaFile.getParent(),
executionMetaFile.getName() + ".tmp");
new ObjectMapper().writeValue(executionTempMetaFile, getExecutionsCache());
Files.move(executionTempMetaFile.toPath(), executionMetaFile.toPath(), REPLACE_EXISTING);
} catch (IOException e) {
log.error("Failed writing execution meta data", e);
}
Expand Down

0 comments on commit d6b19e0

Please sign in to comment.