Example #1
0
gboolean
get_extra_chunk_info(const char *pathname, GError ** error, struct chunk_textinfo_extra_s *chunk_textinfo_extra){
	struct attr_handle_s *attr_handle;
	GError *local_error = NULL;

	if(!_load_attr_from_file(pathname, &attr_handle, &local_error)){
		SETERROR(error, "Failed to init the attribute management context : %s", local_error->message);
		g_clear_error(&local_error);
		return FALSE;
	}
	
	if (!_get_attr_from_handle(attr_handle, &local_error, ATTR_DOMAIN,\
		ATTR_NAME_CHUNK_COMPRESSED_SIZE, &(chunk_textinfo_extra->compressedsize)))
		goto error_get_attr;
	if (!_get_attr_from_handle(attr_handle, &local_error, ATTR_DOMAIN,\
		ATTR_NAME_CHUNK_METADATA_COMPRESS, &(chunk_textinfo_extra->metadatacompress)))
		goto error_get_attr;
	
	_clean_attr_handle(attr_handle, FALSE);
	return TRUE;

error_get_attr:
	SETERROR(error, "Failed to get attr : %s", local_error->message);
	g_clear_error(&local_error);
	_clean_attr_handle(attr_handle, FALSE);
	return FALSE;
}
Example #2
0
gboolean
get_rawx_info_in_attr(const char *pathname, GError ** error,
		struct content_textinfo_s * content, struct chunk_textinfo_s * chunk)
{
	struct attr_handle_s *attr_handle = NULL;
	GError *e = NULL;

	if (!_load_attr_from_file(pathname, &attr_handle, &e)) {
		SETERROR(error, "Failed to init the attribute management context : %s",
				e->message);
		g_clear_error(&e);
		return FALSE;
	}

	if (chunk) {
		GET(ATTR_NAME_CHUNK_ID, chunk->id);
		GET(ATTR_NAME_CHUNK_SIZE, chunk->size);
		GET(ATTR_NAME_CHUNK_POS, chunk->position);
		GET(ATTR_NAME_CHUNK_HASH, chunk->hash);
		GET(ATTR_NAME_CHUNK_METADATA, chunk->metadata);
	}

	if (content) {
		GET(ATTR_NAME_CONTENT_CONTAINER, content->container_id);
		GET(ATTR_NAME_CONTENT_ID, content->content_id);
		GET(ATTR_NAME_CONTENT_PATH, content->path);
		GET(ATTR_NAME_CONTENT_VERSION, content->version);
		GET(ATTR_NAME_CONTENT_SIZE, content->size);
		GET(ATTR_NAME_CONTENT_NBCHUNK, content->chunk_nb);

		GET(ATTR_NAME_CONTENT_STGPOL, content->storage_policy);
		GET(ATTR_NAME_CONTENT_CHUNKMETHOD, content->chunk_method);
		GET(ATTR_NAME_CONTENT_MIMETYPE, content->mime_type);
	}

	_clean_attr_handle(attr_handle, FALSE);
	return TRUE;

error_get_attr:
	SETERROR(error, "Failed to get attr : %s", e->message);
	g_clear_error(&e);
	_clean_attr_handle(attr_handle, FALSE);
	return FALSE;
}
Example #3
0
static gboolean
_load_attr_from_file(const char *chunk_path, struct attr_handle_s** attr_handle, GError ** error)
{
	struct attr_handle_s *ah = NULL;
	GError *local_error = NULL;

	if (!(ah = _alloc_attr_handle(chunk_path))) {
		SETERRCODE(error, ENOMEM, "Memory allocation failure");
		return FALSE;
	}

	if (!_load_from_xattr(ah, &local_error)) {
		if (!local_error) {
			SETERRCODE(&local_error, 500, "Failed to load xattr : unknown error");
			goto error_and_exit;
		}
		else if (local_error->code != ENOTSUP)
			goto error_and_exit;
		else {
			g_clear_error(&local_error);
			if (!_load_from_file_attr(ah, &local_error))
				goto error_and_exit;
		}
	}

	if (local_error)
		g_clear_error(&local_error);
	*error = NULL;
	*attr_handle = ah;
	return TRUE;

error_and_exit:
	if (error)
		*error = local_error;
	else if (local_error)
		g_clear_error(&local_error);
	_clean_attr_handle(ah, FALSE);
	return FALSE;
}
Example #4
0
gboolean
set_rawx_full_info_in_attr(const char *p, int filedes, GError **error,
		struct content_textinfo_s * content, struct chunk_textinfo_s * chunk,
		const char* compression_info, const char* compressed_size)
{
	struct attr_handle_s *attr_handle;
	GError *e = NULL;

	if (!_lazy_load_attr_from_file(p, &attr_handle, &e)) {
		SETERROR(error, "Failed to init the attribute management context : %s", e->message);
		g_clear_error(&e);
		return FALSE;
	}

	if (chunk) {
		_up(chunk->hash);

		SET(ATTR_NAME_CHUNK_ID, chunk->id);
		SET(ATTR_NAME_CHUNK_SIZE, chunk->size);
		SET(ATTR_NAME_CHUNK_HASH, chunk->hash);
		SET(ATTR_NAME_CHUNK_POS, chunk->position);
		SET(ATTR_NAME_CHUNK_METADATA, chunk->metadata);
	}

	if (content) {
		_up(content->container_id);
		_up(content->content_id);

		SET(ATTR_NAME_CONTENT_CONTAINER, content->container_id);
		SET(ATTR_NAME_CONTENT_ID, content->content_id);
		SET(ATTR_NAME_CONTENT_PATH, content->path);
		SET(ATTR_NAME_CONTENT_VERSION, content->version);
		SET(ATTR_NAME_CONTENT_SIZE, content->size);
		SET(ATTR_NAME_CONTENT_NBCHUNK, content->chunk_nb);

		SET(ATTR_NAME_CONTENT_STGPOL, content->storage_policy);
		SET(ATTR_NAME_CONTENT_MIMETYPE, content->mime_type);
		SET(ATTR_NAME_CONTENT_CHUNKMETHOD, content->chunk_method);
	}

	SET(ATTR_NAME_CHUNK_COMPRESSED_SIZE, compressed_size);
	SET(ATTR_NAME_CHUNK_METADATA_COMPRESS, compression_info);

	gboolean rc;
	if (filedes < 0)
		rc = _commit_attr_handle(attr_handle, &e);
	else
		rc = _commit_v2_attr_handle(filedes, attr_handle, &e);

	if (!rc) {
		SETERROR(error, "Could not write all the attributes on disk : %s", e->message);
		g_clear_error(&e);
		_clean_attr_handle(attr_handle, FALSE);
		return FALSE;
	}

	_clean_attr_handle(attr_handle, FALSE);
	return TRUE;

error_set_attr:
	SETERROR(error, "Failed to set attr in handle : %s", e->message);
	g_clear_error(&e);
	_clean_attr_handle(attr_handle, FALSE);
	return FALSE;
}