struct KeywordCounter *counter = value;
if (counter->count >= tc->move_threshold)
- GNUNET_FS_uri_ksk_add_keyword (tc->pos->ksk_uri, counter->value, GNUNET_NO);
+ {
+ if (NULL == tc->pos->ksk_uri)
+ tc->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &counter->value);
+ else
+ GNUNET_FS_uri_ksk_add_keyword (tc->pos->ksk_uri, counter->value, GNUNET_NO);
+ }
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (tc->keywordcounter,
key,
struct MetaCounter *counter = value;
if (counter->count >= tc->move_threshold)
+ {
+ if (NULL == tc->pos->meta)
+ tc->pos->meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_CONTAINER_meta_data_insert (tc->pos->meta,
counter->plugin_name,
counter->type,
counter->format,
counter->data_mime_type, counter->data,
counter->data_size);
+ }
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (tc->metacounter,
key,
}
/* consider adding filename to directory meta data */
- if (tree->is_directory)
+ if (tree->is_directory == GNUNET_YES)
{
const char *user = getenv ("USER");
if ( (user == NULL) ||
(0 != strncasecmp (user, tree->short_filename, strlen(user))))
{
/* only use filename if it doesn't match $USER */
+ if (NULL == tree->meta)
+ tree->meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_CONTAINER_meta_data_insert (tree->meta, "<libgnunetfs>",
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
EXTRACTOR_METAFORMAT_UTF8,
/* now, count keywords and meta data in children */
for (pos = tree->children_head; NULL != pos; pos = pos->next)
{
- GNUNET_CONTAINER_meta_data_iterate (pos->meta, &add_to_meta_counter, tc->metacounter);
- GNUNET_FS_uri_ksk_get_keywords (pos->ksk_uri, &add_to_keyword_counter, tc->keywordcounter);
+ if (NULL != pos->meta)
+ GNUNET_CONTAINER_meta_data_iterate (pos->meta, &add_to_meta_counter, tc->metacounter);
+ if (NULL != pos->ksk_uri)
+ GNUNET_FS_uri_ksk_get_keywords (pos->ksk_uri, &add_to_keyword_counter, tc->keywordcounter);
}
/* calculate threshold for moving keywords / meta data */
for (pos = tree->children_head; NULL != pos; pos = pos->next)
{
tc->pos = pos;
- GNUNET_FS_uri_ksk_get_keywords (pos->ksk_uri, &remove_high_frequency_keywords, tc);
+ if (NULL != pos->ksk_uri)
+ {
+ struct GNUNET_FS_Uri *ksk_uri_copy = GNUNET_FS_uri_dup (pos->ksk_uri);
+ GNUNET_FS_uri_ksk_get_keywords (ksk_uri_copy, &remove_high_frequency_keywords, tc);
+ GNUNET_FS_uri_destroy (ksk_uri_copy);
+ }
}
/* add high-frequency meta data and keywords to parent */
GNUNET_CONTAINER_multihashmap_destroy (tc.metacounter);
}
+
+/**
+ * Release memory of a share item tree.
+ *
+ * @param toplevel toplevel of the tree to be freed
+ */
+void
+GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel)
+{
+ struct GNUNET_FS_ShareTreeItem *pos;
+
+ while (NULL != (pos = toplevel->children_head))
+ GNUNET_FS_share_tree_free (pos);
+ if (NULL != toplevel->parent)
+ GNUNET_CONTAINER_DLL_remove (toplevel->parent->children_head,
+ toplevel->parent->children_tail,
+ toplevel);
+ if (NULL != toplevel->meta)
+ GNUNET_CONTAINER_meta_data_destroy (toplevel->meta);
+ if (NULL != toplevel->ksk_uri)
+ GNUNET_FS_uri_destroy (toplevel->ksk_uri);
+ GNUNET_free_non_null (toplevel->filename);
+ GNUNET_free_non_null (toplevel->short_filename);
+ GNUNET_free (toplevel);
+}
+
/* end fs_sharetree.c */