Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Writing snapshot files now performs atomic writes.

  • Loading branch information...
commit 94afbfb6d292407051b578b98020c7edfadaf3a5 1 parent 8048b1a
Nick Gerakines authored

Showing 1 changed file with 10 additions and 2 deletions. Show diff stats Hide diff stats

  1. +10 2 src/barbershop.c
12 src/barbershop.c
@@ -343,9 +343,14 @@ void load_snapshot(char *filename) {
343 343 void sync_to_disk(PoolNode *head, char *filename) {
344 344 FILE *out_file;
345 345
346   - remove(filename);
  346 + time_t now;
  347 + time(&now);
  348 + char tmp_file[32];
  349 + sprintf(tmp_file, "barbershop.%d.tmp", (int)now);
347 350
348   - out_file = fopen(filename, "w");
  351 + remove(tmp_file);
  352 +
  353 + out_file = fopen(tmp_file, "w");
349 354 if (out_file == NULL) {
350 355 fprintf(stderr, "Can not open output file\n");
351 356 exit (8);
@@ -362,6 +367,9 @@ void sync_to_disk(PoolNode *head, char *filename) {
362 367 }
363 368
364 369 fclose(out_file);
  370 +
  371 + rename(tmp_file, filename);
  372 +
365 373 return;
366 374 }
367 375

0 comments on commit 94afbfb

Please sign in to comment.
Something went wrong with that request. Please try again.