Exemplo n.º 1
0
static void
test_set_content_property_again(gs_grid_storage_t * gs)
{
	gs_error_t **err = NULL;
	gchar **result = NULL;

	char *nameRef = test_init(gs, "Ref_linked", NULL);
	char *nameCont = gen_random(7);
	gs_container_t *container = container_init(gs, nameCont);

	hc_ul_content_from_file(gs, nameCont, "Content", "file_test.txt", err);
	gs_content_t *content = gs_get_content_from_path(container, "Content", err);

	char *props = "key1=value1";
	char *props2 = "key1=value2";

	hc_set_content_property(content, &props, err);
	hc_set_content_property(content, &props2, err);
	g_assert_true(err == NULL);

	hc_get_content_properties(content, &result, err);
	if (strcmp(result[0], "key1=value2"))
		g_test_fail();

	gs_content_free(content);
	test_end(gs, nameRef, container);
}
Exemplo n.º 2
0
gs_error_t *
hc_delete_content(gs_grid_storage_t *hc, struct hc_url_s *url)
{
	gs_error_t *e = NULL;
	gs_container_t *c = NULL;
	gs_content_t *content = NULL;

	c = gs_get_storage_container(hc, hc_url_get(url, HCURL_REFERENCE),NULL, 0, &e);
	if(NULL != c) {
		const gchar *version = hc_url_get(url, HCURL_VERSION);
		// First try
		content = gs_get_content_from_path_and_version (c, hc_url_get(url, HCURL_PATH), version, &e);
		if (content == NULL && e != NULL && e->code == CODE_CONTENT_NOTFOUND && !version) {
			// Last version is probably marked deleted, so a "get" without
			// version fails. We need to specify we want the latest, even
			// if it's deleted, so we can undelete it.
			version = HCURL_LATEST_VERSION;
			gs_error_free(e);
			e = NULL;
			// Second try
			content = gs_get_content_from_path_and_version (c, hc_url_get(url, HCURL_PATH), version, &e);
		}
		if (NULL != content) {
			if(gs_destroy_content (content, &e)) {
				GRID_DEBUG("Content %s deleted\n", hc_url_get(url, HCURL_PATH));
			}
			gs_content_free(content);
		}
		gs_container_free(c);
	}
	return e;
}
Exemplo n.º 3
0
/*
static void
test_delete_content_property(gs_grid_storage_t * gs)
{
	gs_error_t **err = NULL;
	gchar **result = NULL;

	char *nameRef = test_init(gs, "Ref_linked", NULL);
	char *nameCont = gen_random(7);
	gs_container_t *container = container_init(gs, nameCont);

	hc_ul_content_from_file(gs, nameCont, "Content", "file_test.txt", err);
	gs_content_t *nameContent =
		gs_get_content_from_path(container, "Content", err);

	char *props[] = { "key1=value1", "key2=value2", NULL };
	char *propDel[] = { "key1", NULL };
	hc_set_content_property(nameContent, props, err);

	hc_delete_content_property(nameContent, propDel, err);
	g_assert_true(err == NULL);

	hc_get_content_properties(nameContent, &result, err);
	g_assert_true(err == NULL);
	if (result == NULL)
		g_test_fail();
	else
		g_assert_true(strcmp(result[0], "key2=value2") == 0);

	gs_content_free(nameContent);
	test_end(gs, nameRef, container);
}
*/
static void
test_copy_content(gs_grid_storage_t * gs)
{
	gs_error_t **err = NULL;

	char *nameRef = test_init(gs, "Ref_linked", NULL);
	char *nameCont = gen_random(7);
	gs_container_t *container = container_init(gs, nameCont);

	hc_ul_content_from_file(gs, nameCont, "Content", "file_test.txt", err);
	gs_content_t *nameContent =
		gs_get_content_from_path(container, "Content", err);

	hc_copy_content(container, "Content", "Content_copy", err);
	g_assert_true(err == NULL);

	gs_content_t *nameContent2 =
		gs_get_content_from_path(container, "Content_copy", err);
	g_assert_true(nameContent != NULL);

	gs_content_free(nameContent);
	gs_content_free(nameContent2);
	test_end(gs, nameRef, container);
}
Exemplo n.º 4
0
gs_content_t*
gs_container_get_content_from_raw(gs_grid_storage_t *client,
		struct meta2_raw_content_s *raw, gs_error_t **gserr)
{
	gchar str_hex[STRLEN_CONTAINERID];
	struct gs_container_location_s *location;
	gs_content_t *result = NULL;

	if (!client || !raw) {
		GSERRORSET(gserr, "Invalid parameter (%p %p)", client, raw);
		return NULL;
	}

	/* Now locates the content's container */
	container_id_to_string(raw->container_id, str_hex, sizeof(str_hex));
	location = gs_locate_container_by_hexid(client, str_hex, gserr);
	if (!location) {
		GSERRORSET(gserr, "Container reference not found for CID[%s]", str_hex);
		return NULL;
	}

	/* Container found, alright ... */

	result = calloc(1, sizeof(gs_content_t));
	if (!result) {
		gs_container_location_free(location);
		GSERRORCODE(gserr, ENOMEM, "Memory allocation failure");
		return NULL;
	}

	/* Initiates the content part */
	g_strlcpy(result->info.path, raw->path, MIN(sizeof(result->info.path)-1,sizeof(raw->path)));
	result->info.size = raw->size;
	map_content_from_raw(result, raw);

	/* Initiates the container part */
	result->info.container = gs_container_init_from_location(client, location, gserr);
	if (!result->info.container) {
		gs_container_location_free(location);
		gs_content_free(result);
		GSERRORCODE(gserr, ENOMEM, "Memory allocation failure");
		return NULL;
	}

	DEBUG("Resolved container ID[%s]", location->container_hexid);
	gs_container_location_free(location);
	return result;
}
Exemplo n.º 5
0
static gs_error_t *
_dl_nocache(gs_container_t *c, struct hc_url_s *url,
		gs_download_info_t *dlinfo, gchar *stgpol)
{
	gs_error_t *e = NULL;
	GError *err = NULL;
	gs_content_t *content = NULL;
	namespace_info_t *ni = NULL;
	GSList *filtered = NULL, *beans = NULL;

	/*find the content*/
	content  = gs_get_content_from_path_full(c, hc_url_get(url, HCURL_PATH),
			hc_url_get(url, HCURL_SNAPORVERS), &filtered, &beans, &e);

	if(NULL != content) {
		GRID_DEBUG("Content %s found in container %s\n",
				hc_url_get(url, HCURL_PATH), hc_url_get(url, HCURL_REFERENCE));

		ni = get_namespace_info(hc_url_get(url, HCURL_NS), &err);
		if (!ni) {
			GSERRORCAUSE(&e, err, "Cannot get namespace info for NS [%s]",
					hc_url_get(url, HCURL_NS));
			g_clear_error(&err);
			return e;
		}

		namespace_info_copy(ni, &(content->info.container->info.gs->ni), &err);

		/*download the content*/
		(void) gs_download_content_full (content, dlinfo, stgpol, filtered,
				beans, &e);
		namespace_info_clear(ni);
		g_free(ni);
		gs_content_free (content);
		g_slist_free(filtered);
		_bean_cleanl2(beans);
		return e;
	}

	g_printerr("'%s' not found in '%s'\n", hc_url_get(url, HCURL_PATH),
			hc_url_get(url, HCURL_REFERENCE));
	return e;
}
Exemplo n.º 6
0
static void
test_set_content_storage_policy_wrong(gs_grid_storage_t * gs)	// to be improved
{
	gs_error_t **err = NULL;

	char *nameRef = test_init(gs, "Ref_linked", NULL);
	char *nameCont = gen_random(7);
	gs_container_t *container = container_init(gs, nameCont);

	hc_ul_content_from_file(gs, nameCont, "Content", "file_test.txt", err);
	gs_content_t *content = gs_get_content_from_path(container, "Content", err);

	hc_set_content_storage_policy(container, "Content", "Wrong_stgpol", err);
	if (err == NULL)
		g_test_fail();

	gs_content_free(content);
	test_end(gs, nameRef, container);
}
Exemplo n.º 7
0
gs_error_t *
hc_func_get_content_properties(gs_grid_storage_t *hc, struct hc_url_s *url, char ***result)
{
	gs_error_t *e = NULL;
	gs_container_t *c = NULL;
	gs_content_t *content = NULL;

	c = gs_get_storage_container(hc, hc_url_get(url, HCURL_REFERENCE), NULL, 0, &e);
	if (NULL != c) {
		if (hc_url_has(url, HCURL_PATH)) {
			content = gs_get_content_from_path_and_version (c,
					hc_url_get(url, HCURL_PATH), hc_url_get(url, HCURL_VERSION),
					&e);
			if(NULL != content) {
				hc_get_content_properties(content,result,&e);
				gs_content_free(content);
			}
		} else {
			e = hc_get_container_global_properties(c, result);
		}
		gs_container_free(c);
	}
	return e;
}
Exemplo n.º 8
0
static void
test_set_content_property_wrong(gs_grid_storage_t * gs)	// to be improved
{
	gs_error_t **err = NULL;
	gchar **result = NULL;

	char *nameRef = test_init(gs, "Ref_linked", NULL);
	char *nameCont = gen_random(7);
	gs_container_t *container = container_init(gs, nameCont);

	hc_ul_content_from_file(gs, nameCont, "Content", "file_test.txt", err);
	gs_content_t *content = gs_get_content_from_path(container, "Content", err);

	char *props[] = { "wrong_property" };

	hc_set_content_property(content, props, err);
	if (err == NULL)
		g_test_fail();

	hc_get_content_properties(content, &result, err);

	gs_content_free(content);
	test_end(gs, nameRef, container);
}