-fix
[oweals/gnunet.git] / src / fs / gnunet-service-fs_indexing.c
index c7bff3a9d016c0a5cfb64f3d8cd67b6cbf605781..b56301962ee707ae7f34e7d9f9a9dc8179c98e96 100644 (file)
@@ -228,8 +228,7 @@ signal_index_ok (struct IndexInfo *ii)
                 ("Index request received for file `%s' is already indexed as `%s'.  Permitting anyway.\n"),
                 ii->filename,
                 (const char *) GNUNET_CONTAINER_multihashmap_get (ifm,
-                                                                  &ii->
-                                                                  file_id));
+                                                                  &ii->file_id));
     GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
                                                 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
     GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
@@ -266,10 +265,8 @@ hash_for_index_val (void *cls, const GNUNET_HashCode * res)
                 _
                 ("Hash mismatch trying to index file `%s' which has hash `%s'\n"),
                 ii->filename, GNUNET_h2s (res));
-#if DEBUG_FS
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Wanted `%s'\n",
                 GNUNET_h2s (&ii->file_id));
-#endif
     GNUNET_SERVER_transmit_context_append_data (ii->tc, NULL, 0,
                                                 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
     GNUNET_SERVER_transmit_context_run (ii->tc, GNUNET_TIME_UNIT_MINUTES);
@@ -330,11 +327,8 @@ GNUNET_FS_handle_index_start (void *cls, struct GNUNET_SERVER_Client *client,
   ii->filename = (const char *) &ii[1];
   memcpy (&ii[1], fn, slen);
   ii->file_id = ism->file_id;
-#if DEBUG_FS
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message for file `%s'\n",
               "START_INDEX", ii->filename);
-#endif
-
   ii->tc = GNUNET_SERVER_transmit_context_create (client);
   mydev = 0;
   myino = 0;
@@ -347,12 +341,10 @@ GNUNET_FS_handle_index_start (void *cls, struct GNUNET_SERVER_Client *client,
     GNUNET_free (fn);
     return;
   }
-#if DEBUG_FS
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Mismatch in file identifiers (%llu != %llu or %u != %u), need to hash.\n",
               (unsigned long long) ino, (unsigned long long) myino,
               (unsigned int) dev, (unsigned int) mydev);
-#endif
   /* slow validation, need to hash full file (again) */
   ii->fhc =
       GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, fn,
@@ -447,8 +439,8 @@ GNUNET_FS_handle_unindex (void *cls, struct GNUNET_SERVER_Client *client,
         prev->next = next;
       GNUNET_break (GNUNET_OK ==
                     GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id,
-                                                          (void *) pos->
-                                                          filename));
+                                                          (void *)
+                                                          pos->filename));
       GNUNET_free (pos);
       found = GNUNET_YES;
     }
@@ -458,11 +450,9 @@ GNUNET_FS_handle_unindex (void *cls, struct GNUNET_SERVER_Client *client,
     }
     pos = next;
   }
-#if DEBUG_FS
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Client requested unindexing of file `%s': %s\n",
               GNUNET_h2s (&um->file_id), found ? "found" : "not found");
-#endif
   if (GNUNET_YES == found)
     write_index_list ();
   tc = GNUNET_SERVER_transmit_context_create (client);
@@ -478,10 +468,13 @@ GNUNET_FS_handle_unindex (void *cls, struct GNUNET_SERVER_Client *client,
  *
  * @param cls unused
  * @param success did the deletion work?
+ * @param min_expiration minimum expiration time required for content to be stored
  * @param msg error message
  */
 static void
-remove_cont (void *cls, int success, const char *msg)
+remove_cont (void *cls, int success, 
+            struct GNUNET_TIME_Absolute min_expiration,
+            const char *msg)
 {
   if (GNUNET_OK != success)
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -539,9 +532,17 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, uint32_t size,
   odb = (const struct OnDemandBlock *) data;
   off = GNUNET_ntohll (odb->offset);
   fn = (const char *) GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
-  fh = NULL;
-  if ((NULL == fn) ||
-      (NULL ==
+  if ((NULL == fn) || (0 != ACCESS (fn, R_OK)))
+  {
+    GNUNET_STATISTICS_update (GSF_stats,
+                              gettext_noop
+                              ("# index blocks removed: original file inaccessible"),
+                              1, GNUNET_YES);
+    GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1,
+                             GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
+    return GNUNET_SYSERR;
+  }
+  if ((NULL ==
        (fh =
         GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ,
                                GNUNET_DISK_PERM_NONE))) ||
@@ -573,10 +574,8 @@ GNUNET_FS_handle_on_demand_block (const GNUNET_HashCode * key, uint32_t size,
                              GNUNET_TIME_UNIT_FOREVER_REL, &remove_cont, NULL);
     return GNUNET_SYSERR;
   }
-#if DEBUG_FS
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "On-demand encoded block for query `%s'\n", GNUNET_h2s (key));
-#endif
   cont (cont_cls, key, nsize, edata, GNUNET_BLOCK_TYPE_FS_DBLOCK, priority,
         anonymity, expiration, uid);
   return GNUNET_OK;