-fixing #2578
[oweals/gnunet.git] / src / fs / fs_unindex.c
index bf619b75acf127c48e66969231b7b984044d99ea..221760328c8499440a4677206129ed16a1dfb852 100644 (file)
@@ -223,7 +223,7 @@ process_fs_response (void *cls, const struct GNUNET_MessageHeader *msg)
 
   if (uc->client != NULL)
   {
-    GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
+    GNUNET_CLIENT_disconnect (uc->client);
     uc->client = NULL;
   }
   if (uc->state != UNINDEX_STATE_FS_NOTIFY)
@@ -341,12 +341,13 @@ unindex_directory_scan_cb (void *cls,
     {
       uc->ksk_uri = GNUNET_FS_uri_dup (directory_scan_result->ksk_uri);
       uc->state = UNINDEX_STATE_DS_REMOVE_KBLOCKS;
-      uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service."));
       GNUNET_FS_unindex_sync_ (uc);
       GNUNET_FS_unindex_do_remove_kblocks_ (uc);
     }
     else
     {
+      uc->emsg = GNUNET_strdup (_("Failed to get KSKs from directory scan."));
+      GNUNET_FS_unindex_sync_ (uc);
       unindex_finish (uc);
     }
     GNUNET_FS_share_tree_free (directory_scan_result);
@@ -355,11 +356,15 @@ unindex_directory_scan_cb (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                _("Internal error scanning `%s'.\n"),
                uc->filename);
+    GNUNET_FS_directory_scan_abort (uc->dscan);
+    uc->dscan = NULL;
+    uc->emsg = GNUNET_strdup (_("Failed to get KSKs from directory scan."));
+    GNUNET_FS_unindex_sync_ (uc);
+    unindex_finish (uc);
     break;
   default:
     break;
   }
-
 }
 
 
@@ -437,7 +442,7 @@ continue_after_remove (void *cls,
  */
 static void
 process_kblock_for_unindex (void *cls,
-                           const GNUNET_HashCode * key,
+                           const struct GNUNET_HashCode * key,
                            size_t size, const void *data,
                            enum GNUNET_BLOCK_Type type,
                            uint32_t priority,
@@ -545,7 +550,7 @@ GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc)
   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
   struct GNUNET_CRYPTO_RsaPrivateKey *pk;
 
-  if (NULL != uc->dsh)
+  if (NULL == uc->dsh)
     uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg);
   if (NULL == uc->dsh)
   {
@@ -610,7 +615,8 @@ unindex_extract_keywords (void *cls, const struct GNUNET_SCHEDULER_TaskContext *
 void
 GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
 {
-  uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg);
+  if (NULL == uc->dsh)
+    uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg);
   if (NULL == uc->dsh)
   {
     uc->state = UNINDEX_STATE_ERROR;
@@ -648,7 +654,7 @@ GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
  * @param file_id computed hash, NULL on error
  */
 void
-GNUNET_FS_unindex_process_hash_ (void *cls, const GNUNET_HashCode * file_id)
+GNUNET_FS_unindex_process_hash_ (void *cls, const struct GNUNET_HashCode * file_id)
 {
   struct GNUNET_FS_UnindexContext *uc = cls;
 
@@ -708,7 +714,7 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls)
   }
   if (uc->client != NULL)
   {
-    GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
+    GNUNET_CLIENT_disconnect (uc->client);
     uc->client = NULL;
   }
   if (NULL != uc->dsh)
@@ -803,7 +809,7 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc)
   }
   if (uc->client != NULL)
   {
-    GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
+    GNUNET_CLIENT_disconnect (uc->client);
     uc->client = NULL;
   }
   if (NULL != uc->dsh)
@@ -840,6 +846,7 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc)
                                   (uc->state ==
                                    UNINDEX_STATE_COMPLETE) ? uc->file_size : 0);
   GNUNET_break (NULL == uc->client_info);
+  GNUNET_free_non_null (uc->emsg);
   GNUNET_free (uc->filename);
   GNUNET_free (uc);
 }