fixing 1584
[oweals/gnunet.git] / src / fs / fs_publish.c
index 277a783c52f8c2e86a5ee342361c7d80f2e889d9..73fc710e18dc33b73960ac6b21473ed69102aa70 100644 (file)
@@ -113,6 +113,11 @@ publish_cleanup (void *cls,
 {
   struct GNUNET_FS_PublishContext *pc = cls;
 
+  if (pc->fhc != NULL)
+    {
+      GNUNET_CRYPTO_hash_file_cancel (pc->fhc);
+      pc->fhc = NULL;
+    }
   GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
   if (pc->namespace != NULL)
     GNUNET_FS_namespace_delete (pc->namespace, GNUNET_NO);
@@ -482,6 +487,15 @@ encode_cont (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Finished with tree encoder\n");
 #endif  
+  /* final progress event */
+  pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS;
+  pi.value.publish.specifics.progress.data = NULL;
+  pi.value.publish.specifics.progress.offset = GNUNET_FS_uri_chk_get_file_size (p->chk_uri);
+  pi.value.publish.specifics.progress.data_len = 0;
+  pi.value.publish.specifics.progress.depth = 0;
+  p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, 
+                                                  GNUNET_FS_uri_chk_get_file_size (p->chk_uri));
+
   /* continue with main */
   sc->upload_task 
     = GNUNET_SCHEDULER_add_with_priority (sc->h->sched,
@@ -553,7 +567,7 @@ block_proc (void *cls,
       odb.offset = GNUNET_htonll (offset);
       odb.file_id = p->data.file.file_id;
       GNUNET_DATASTORE_put (sc->dsh,
-                           sc->rid,
+                           (p->is_directory) ? 0 : sc->rid,
                            query,
                            sizeof(struct OnDemandBlock),
                            &odb,
@@ -575,7 +589,7 @@ block_proc (void *cls,
              (unsigned int) block_size);
 #endif
   GNUNET_DATASTORE_put (sc->dsh,
-                       sc->rid,
+                       (p->is_directory) ? 0 : sc->rid,
                        query,
                        block_size,
                        block,
@@ -788,6 +802,7 @@ hash_for_index_cb (void *cls,
   uint64_t ino;
   char *fn;
 
+  sc->fhc = NULL;
   p = sc->fi_pos;
   if (NULL == res) 
     {
@@ -1023,12 +1038,12 @@ GNUNET_FS_publish_main_ (void *cls,
       else
        {
          p->start_time = GNUNET_TIME_absolute_get ();
-         GNUNET_CRYPTO_hash_file (pc->h->sched,
-                                  GNUNET_SCHEDULER_PRIORITY_IDLE,
-                                  p->filename,
-                                  HASHING_BLOCKSIZE,
-                                  &hash_for_index_cb,
-                                  pc);
+         pc->fhc = GNUNET_CRYPTO_hash_file (pc->h->sched,
+                                            GNUNET_SCHEDULER_PRIORITY_IDLE,
+                                            p->filename,
+                                            HASHING_BLOCKSIZE,
+                                            &hash_for_index_cb,
+                                            pc);
        }
       return;
     }
@@ -1090,6 +1105,7 @@ fip_signal_start(void *cls,
       left = left * sizeof (struct ContentHashKey);
       sc->reserve_space += left;
     }
+  sc->reserve_entries++;
   /* entries and space for keywords */
   if (NULL != *uri)
     {
@@ -1235,6 +1251,7 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
   struct GNUNET_FS_PublishContext *ret;
   struct GNUNET_DATASTORE_Handle *dsh;
 
+  GNUNET_assert (NULL != h);
   if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
     {
       dsh = GNUNET_DATASTORE_connect (h->cfg,