unindex syncing
authorChristian Grothoff <christian@grothoff.org>
Sat, 1 May 2010 11:16:23 +0000 (11:16 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 1 May 2010 11:16:23 +0000 (11:16 +0000)
src/fs/fs.c

index 4174614041d832762dbfa64ec7e76b0731cdcdb9..c0271282a4565da04f43a0796b410f7fc9188813 100644 (file)
@@ -1158,7 +1158,7 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
       return;
     }
   wh = get_write_handle (pc->h, "publish", pc->serialization);
- if ( (GNUNET_OK !=
 if ( (GNUNET_OK !=
        GNUNET_BIO_write_string (wh, pc->nid)) ||
        (GNUNET_OK !=
        GNUNET_BIO_write_string (wh, pc->nuid)) ||
@@ -1201,7 +1201,45 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc)
 void
 GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc)
 {
-  /* FIXME */
+  struct GNUNET_BIO_WriteHandle *wh;
+
+  if (UNINDEX_STATE_ABORTED == uc->state)
+    return;
+  if (NULL == uc->serialization)
+    uc->serialization = make_serialization_file_name (uc->h,
+                                                     "unindex");
+  if (NULL == uc->serialization)
+    return;
+  wh = get_write_handle (uc->h, "unindex", uc->serialization);
+  if ( (GNUNET_OK !=
+       GNUNET_BIO_write_string (wh, uc->filename)) ||
+       (GNUNET_OK !=
+       GNUNET_BIO_write_int64 (wh, uc->file_size)) ||
+       (GNUNET_OK !=
+       GNUNET_BIO_write_int64 (wh, uc->start_time.value)) ||
+       (GNUNET_OK !=
+       GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) ||
+       ( (uc->state == UNINDEX_STATE_FS_NOTIFY) &&
+        (GNUNET_OK !=
+         GNUNET_BIO_write (wh, &uc->file_id, sizeof (GNUNET_HashCode))) ) ||
+       ( (uc->state == UNINDEX_STATE_ERROR) &&
+        (GNUNET_OK !=
+         GNUNET_BIO_write_string (wh, uc->emsg)) ) )
+    {
+      (void) GNUNET_BIO_write_close (wh);
+      GNUNET_FS_remove_sync_file_ (uc->h, "publish", uc->serialization);
+      GNUNET_free (uc->serialization);
+      uc->serialization = NULL;
+      return;
+    }
+  if (GNUNET_OK !=
+      GNUNET_BIO_write_close (wh))
+    {
+      GNUNET_FS_remove_sync_file_ (uc->h, "unindex", uc->serialization);
+      GNUNET_free (uc->serialization);
+      uc->serialization = NULL;
+      return;     
+    }  
 }