/** * Create SUSPEND event for the given unindex operation * and then clean up our state (without stop signal). * * @param cls the `struct GNUNET_FS_UnindexContext` to signal for */ void GNUNET_FS_unindex_signal_suspend_ (void *cls) { struct GNUNET_FS_UnindexContext *uc = cls; struct GNUNET_FS_ProgressInfo pi; /* FIXME: lots of duplication with unindex_stop here! */ if (uc->dscan != NULL) { GNUNET_FS_directory_scan_abort (uc->dscan); uc->dscan = NULL; } if (NULL != uc->dqe) { GNUNET_DATASTORE_cancel (uc->dqe); uc->dqe = NULL; } if (uc->fhc != NULL) { GNUNET_CRYPTO_hash_file_cancel (uc->fhc); uc->fhc = NULL; } if (NULL != uc->ksk_uri) { GNUNET_FS_uri_destroy (uc->ksk_uri); uc->ksk_uri = NULL; } if (uc->client != NULL) { GNUNET_CLIENT_disconnect (uc->client); uc->client = NULL; } if (NULL != uc->dsh) { GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); uc->dsh = NULL; } if (NULL != uc->tc) { GNUNET_FS_tree_encoder_finish (uc->tc, NULL); uc->tc = NULL; } if (uc->fh != NULL) { GNUNET_DISK_file_close (uc->fh); uc->fh = NULL; } GNUNET_FS_end_top (uc->h, uc->top); pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; GNUNET_FS_unindex_make_status_ (&pi, uc, (uc->state == UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); GNUNET_break (NULL == uc->client_info); GNUNET_free (uc->filename); GNUNET_free_non_null (uc->serialization); GNUNET_free_non_null (uc->emsg); GNUNET_free (uc); }
/** * Obtain the result of the scan after the scan has signalled * completion. Must not be called prior to completion. The 'ds' is * freed as part of this call. * * @param ds directory scanner structure * @return the results of the scan (a directory tree) */ struct GNUNET_FS_ShareTreeItem * GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds) { struct GNUNET_FS_ShareTreeItem *result; /* check that we're actually done */ GNUNET_assert (NULL == ds->helper); /* preserve result */ result = ds->toplevel; ds->toplevel = NULL; GNUNET_FS_directory_scan_abort (ds); return result; }
/** * Function called by the directory scanner as we extract keywords * that we will need to remove UBlocks. * * @param cls the 'struct GNUNET_FS_UnindexContext *' * @param filename which file we are making progress on * @param is_directory #GNUNET_YES if this is a directory, * #GNUNET_NO if this is a file * #GNUNET_SYSERR if it is neither (or unknown) * @param reason kind of progress we are making */ static void unindex_directory_scan_cb (void *cls, const char *filename, int is_directory, enum GNUNET_FS_DirScannerProgressUpdateReason reason) { struct GNUNET_FS_UnindexContext *uc = cls; static struct GNUNET_FS_ShareTreeItem * directory_scan_result; switch (reason) { case GNUNET_FS_DIRSCANNER_FINISHED: directory_scan_result = GNUNET_FS_directory_scan_get_result (uc->dscan); uc->dscan = NULL; if (NULL != directory_scan_result->ksk_uri) { uc->ksk_uri = GNUNET_FS_uri_dup (directory_scan_result->ksk_uri); uc->state = UNINDEX_STATE_DS_REMOVE_KBLOCKS; 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); break; case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: 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; } }
/** * Clean up after completion of an unindex operation. * * @param uc handle */ void GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) { struct GNUNET_FS_ProgressInfo pi; if (uc->dscan != NULL) { GNUNET_FS_directory_scan_abort (uc->dscan); uc->dscan = NULL; } if (NULL != uc->dqe) { GNUNET_DATASTORE_cancel (uc->dqe); uc->dqe = NULL; } if (uc->fhc != NULL) { GNUNET_CRYPTO_hash_file_cancel (uc->fhc); uc->fhc = NULL; } if (uc->client != NULL) { GNUNET_CLIENT_disconnect (uc->client); uc->client = NULL; } if (NULL != uc->dsh) { GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); uc->dsh = NULL; } if (NULL != uc->ksk_uri) { GNUNET_FS_uri_destroy (uc->ksk_uri); uc->ksk_uri = NULL; } if (NULL != uc->tc) { GNUNET_FS_tree_encoder_finish (uc->tc, NULL); uc->tc = NULL; } if (uc->fh != NULL) { GNUNET_DISK_file_close (uc->fh); uc->fh = NULL; } GNUNET_FS_end_top (uc->h, uc->top); if (uc->serialization != NULL) { GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); GNUNET_free (uc->serialization); uc->serialization = NULL; } pi.status = GNUNET_FS_STATUS_UNINDEX_STOPPED; pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; GNUNET_FS_unindex_make_status_ (&pi, 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); }