<commit_before>/*
 * Copyright (C) SUSE LINUX GmbH 2015, all rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) version 3.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/stat.h>

#include "ccan/list/list.h"
#include "lib/exml.h"
#include "lib/op.h"
#include "lib/s3_path.h"
#include "lib/s3_req.h"
#include "lib/conn.h"
#include "lib/util.h"
#include "lib/dbg.h"
#include "lib/file/file_api.h"
#include "lib/file/xmit.h"
#include "lib/file/handle.h"
#include "s3_handle.h"
#include "s3_stat.h"

static int
s3_fstat_obj(struct s3_fh *s3_fh,
	     struct elasto_fstat *fstat)
{
	int ret;
	struct op *op;
	struct s3_rsp_obj_head *obj_head_rsp;

	ret = s3_req_obj_head(&s3_fh->path, &op);
	if (ret < 0) {
		goto err_out;
	}

	ret = elasto_fop_send_recv(s3_fh->conn, op);
	if (ret < 0) {
		goto err_op_free;
	}

	obj_head_rsp = s3_rsp_obj_head(op);
	if (obj_head_rsp == NULL) {
		ret = -ENOMEM;
		goto err_op_free;
	}

	fstat->ent_type = ELASTO_FSTAT_ENT_FILE;
	fstat->size = obj_head_rsp->len;
	fstat->blksize = 0;	/* leave vacant for now */
	fstat->lease_status = ELASTO_FLEASE_UNLOCKED;
	/* flag which values are valid in the stat response */
	fstat->field_mask = (ELASTO_FSTAT_FIELD_TYPE
				| ELASTO_FSTAT_FIELD_SIZE);
	ret = 0;

err_op_free:
	op_free(op);
err_out:
	return ret;
}

static int
s3_fstat_bkt(struct s3_fh *s3_fh,
	     struct elasto_fstat *fstat)
{
	int ret;
	struct op *op;
	struct s3_rsp_bkt_loc_get *bkt_loc_get_rsp;

	ret = s3_req_bkt_loc_get(&s3_fh->path, &op);
	if (ret < 0) {
		goto err_out;
	}

	ret = elasto_fop_send_recv(s3_fh->conn, op);
	if (ret < 0) {
		goto err_op_free;
	}<commit_msg>lib/file/s3: fill fstat.content_type<commit_after>/*
 * Copyright (C) SUSE LINUX GmbH 2015, all rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) version 3.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/stat.h>

#include "ccan/list/list.h"
#include "lib/exml.h"
#include "lib/op.h"
#include "lib/s3_path.h"
#include "lib/s3_req.h"
#include "lib/conn.h"
#include "lib/util.h"
#include "lib/dbg.h"
#include "lib/file/file_api.h"
#include "lib/file/xmit.h"
#include "lib/file/handle.h"
#include "s3_handle.h"
#include "s3_stat.h"

static int
s3_fstat_obj(struct s3_fh *s3_fh,
	     struct elasto_fstat *fstat)
{
	int ret;
	struct op *op;
	struct s3_rsp_obj_head *obj_head_rsp;
	size_t ctlen;

	ret = s3_req_obj_head(&s3_fh->path, &op);
	if (ret < 0) {
		goto err_out;
	}

	ret = elasto_fop_send_recv(s3_fh->conn, op);
	if (ret < 0) {
		goto err_op_free;
	}

	obj_head_rsp = s3_rsp_obj_head(op);
	if (obj_head_rsp == NULL) {
		ret = -ENOMEM;
		goto err_op_free;
	}

	fstat->ent_type = ELASTO_FSTAT_ENT_FILE;
	fstat->size = obj_head_rsp->len;
	fstat->blksize = 0;	/* leave vacant for now */
	fstat->lease_status = ELASTO_FLEASE_UNLOCKED;

	ctlen = strlen(obj_head_rsp->content_type);
	if (ctlen >= ARRAY_SIZE(fstat->content_type)) {
		dbg(0, "oversize object content-type\n");
		ret = -EINVAL;
		goto err_op_free;
	}
	strncpy(fstat->content_type, obj_head_rsp->content_type,
		ARRAY_SIZE(fstat->content_type));
	/* flag which values are valid in the stat response */
	fstat->field_mask = (ELASTO_FSTAT_FIELD_TYPE
				| ELASTO_FSTAT_FIELD_SIZE
				| ELASTO_FSTAT_FIELD_CONTENT_TYPE);
	ret = 0;

err_op_free:
	op_free(op);
err_out:
	return ret;
}

static int
s3_fstat_bkt(struct s3_fh *s3_fh,
	     struct elasto_fstat *fstat)
{
	int ret;
	struct op *op;
	struct s3_rsp_bkt_loc_get *bkt_loc_get_rsp;

	ret = s3_req_bkt_loc_get(&s3_fh->path, &op);
	if (ret < 0) {
		goto err_out;
	}

	ret = elasto_fop_send_recv(s3_fh->conn, op);
	if (ret < 0) {
		goto err_op_free;
	}
{'fraction_non_alphanumeric': 0.1251288394145537, 'fraction_numerical': 0.013605442176870748, 'mean_word_length': 4.256771397616468, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2611722', 'n_tokens_mistral': 2070, 'n_tokens_neox': 1994, 'n_words': 505}