gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r18660 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r18660 - gnunet/src/util
Date: Sat, 17 Dec 2011 19:29:09 +0100

Author: grothoff
Date: 2011-12-17 19:29:09 +0100 (Sat, 17 Dec 2011)
New Revision: 18660

Modified:
   gnunet/src/util/container_bloomfilter.c
Log:
-even better error handling

Modified: gnunet/src/util/container_bloomfilter.c
===================================================================
--- gnunet/src/util/container_bloomfilter.c     2011-12-17 18:26:36 UTC (rev 
18659)
+++ gnunet/src/util/container_bloomfilter.c     2011-12-17 18:29:09 UTC (rev 
18660)
@@ -478,9 +478,43 @@
                              GNUNET_DISK_OPEN_READWRITE,
                              GNUNET_DISK_PERM_USER_READ |
                              GNUNET_DISK_PERM_USER_WRITE);
-  if (NULL == bf->fh)
+  if (NULL != bf->fh)
   {
-    /* file did not exist, don't read */
+    /* file existed, try to read it! */
+    must_read = GNUNET_YES;
+    if (GNUNET_OK !=
+       GNUNET_DISK_file_handle_size (bf->fh, &fsize))
+    {
+      GNUNET_DISK_file_close (bf->fh);
+      GNUNET_free (bf);
+      return NULL;
+    }
+    if (fsize == 0)
+    {
+      /* found existing empty file, just overwrite */
+      if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
+      {
+       GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+                            "write");
+       GNUNET_DISK_file_close (bf->fh);
+       GNUNET_free (bf);
+       return NULL;
+      }
+    }
+    else if (fsize != size * 4LL)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Size of file on disk is incorrect for this Bloom filter 
(want %llu, have %llu)\n"),
+                 (unsigned long long) (size * 4LL),
+                 (unsigned long long) fsize);
+      GNUNET_DISK_file_close (bf->fh);
+      GNUNET_free (bf);
+      return NULL;
+    }
+  }
+  else
+  {
+    /* file did not exist, don't read, just create */
     must_read = GNUNET_NO;
     bf->fh =
       GNUNET_DISK_file_open (filename,
@@ -502,28 +536,6 @@
       return NULL;
     }
   }
-  else
-  {
-    /* file existed, try to read it! */
-    must_read = GNUNET_YES;
-    if (GNUNET_OK !=
-       GNUNET_DISK_file_handle_size (bf->fh, &fsize))
-    {
-      GNUNET_DISK_file_close (bf->fh);
-      GNUNET_free (bf);
-      return NULL;
-    }
-    if (fsize != size * 4LL)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                 _("Size of file on disk is incorrect for this Bloom filter 
(want %llu, have %llu)\n"),
-                 (unsigned long long) (size * 4LL),
-                 (unsigned long long) fsize);
-      GNUNET_DISK_file_close (bf->fh);
-      GNUNET_free (bf);
-      return NULL;
-    }
-  }
   bf->filename = GNUNET_strdup (filename);
   /* Alloc block */
   bf->bitArray = GNUNET_malloc_large (size);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]