aboutsummaryrefslogtreecommitdiff
path: root/src/util/container_bloomfilter.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-12-17 18:29:09 +0000
committerChristian Grothoff <christian@grothoff.org>2011-12-17 18:29:09 +0000
commit336c0983364b2899e0f12c97d1eb1820656e7ea3 (patch)
tree19ef9979ce10afa941eeb6e0fb2a1b97bf1cfa90 /src/util/container_bloomfilter.c
parentd5fbdb54ad7c085b22a8ce37979afccd16617a73 (diff)
downloadgnunet-336c0983364b2899e0f12c97d1eb1820656e7ea3.tar.gz
gnunet-336c0983364b2899e0f12c97d1eb1820656e7ea3.zip
-even better error handling
Diffstat (limited to 'src/util/container_bloomfilter.c')
-rw-r--r--src/util/container_bloomfilter.c60
1 files changed, 36 insertions, 24 deletions
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c
index d44c33b0c..7be082f17 100644
--- a/src/util/container_bloomfilter.c
+++ b/src/util/container_bloomfilter.c
@@ -478,9 +478,43 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
478 GNUNET_DISK_OPEN_READWRITE, 478 GNUNET_DISK_OPEN_READWRITE,
479 GNUNET_DISK_PERM_USER_READ | 479 GNUNET_DISK_PERM_USER_READ |
480 GNUNET_DISK_PERM_USER_WRITE); 480 GNUNET_DISK_PERM_USER_WRITE);
481 if (NULL == bf->fh) 481 if (NULL != bf->fh)
482 { 482 {
483 /* file did not exist, don't read */ 483 /* file existed, try to read it! */
484 must_read = GNUNET_YES;
485 if (GNUNET_OK !=
486 GNUNET_DISK_file_handle_size (bf->fh, &fsize))
487 {
488 GNUNET_DISK_file_close (bf->fh);
489 GNUNET_free (bf);
490 return NULL;
491 }
492 if (fsize == 0)
493 {
494 /* found existing empty file, just overwrite */
495 if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
496 {
497 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
498 "write");
499 GNUNET_DISK_file_close (bf->fh);
500 GNUNET_free (bf);
501 return NULL;
502 }
503 }
504 else if (fsize != size * 4LL)
505 {
506 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
507 _("Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"),
508 (unsigned long long) (size * 4LL),
509 (unsigned long long) fsize);
510 GNUNET_DISK_file_close (bf->fh);
511 GNUNET_free (bf);
512 return NULL;
513 }
514 }
515 else
516 {
517 /* file did not exist, don't read, just create */
484 must_read = GNUNET_NO; 518 must_read = GNUNET_NO;
485 bf->fh = 519 bf->fh =
486 GNUNET_DISK_file_open (filename, 520 GNUNET_DISK_file_open (filename,
@@ -502,28 +536,6 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
502 return NULL; 536 return NULL;
503 } 537 }
504 } 538 }
505 else
506 {
507 /* file existed, try to read it! */
508 must_read = GNUNET_YES;
509 if (GNUNET_OK !=
510 GNUNET_DISK_file_handle_size (bf->fh, &fsize))
511 {
512 GNUNET_DISK_file_close (bf->fh);
513 GNUNET_free (bf);
514 return NULL;
515 }
516 if (fsize != size * 4LL)
517 {
518 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
519 _("Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"),
520 (unsigned long long) (size * 4LL),
521 (unsigned long long) fsize);
522 GNUNET_DISK_file_close (bf->fh);
523 GNUNET_free (bf);
524 return NULL;
525 }
526 }
527 bf->filename = GNUNET_strdup (filename); 539 bf->filename = GNUNET_strdup (filename);
528 /* Alloc block */ 540 /* Alloc block */
529 bf->bitArray = GNUNET_malloc_large (size); 541 bf->bitArray = GNUNET_malloc_large (size);