Permalink
Browse files

Writing snapshot files now performs atomic writes.

  • Loading branch information...
1 parent 8048b1a commit 94afbfb6d292407051b578b98020c7edfadaf3a5 @ngerakines committed Mar 8, 2010
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/barbershop.c
View
@@ -343,9 +343,14 @@ void load_snapshot(char *filename) {
void sync_to_disk(PoolNode *head, char *filename) {
FILE *out_file;
- remove(filename);
+ time_t now;
+ time(&now);
+ char tmp_file[32];
+ sprintf(tmp_file, "barbershop.%d.tmp", (int)now);
- out_file = fopen(filename, "w");
+ remove(tmp_file);
+
+ out_file = fopen(tmp_file, "w");
if (out_file == NULL) {
fprintf(stderr, "Can not open output file\n");
exit (8);
@@ -362,6 +367,9 @@ void sync_to_disk(PoolNode *head, char *filename) {
}
fclose(out_file);
+
+ rename(tmp_file, filename);
+
return;
}

0 comments on commit 94afbfb

Please sign in to comment.