<commit_before>%%%--------------------------------------------------------------------
%%% @author <NAME>
%%% @copyright (C) 2015 ACK CYFRONET AGH
%%% This software is released under the MIT license
%%% cited in 'LICENSE.txt'.
%%% @end
%%%--------------------------------------------------------------------
%%% @doc
%%% Common cowboy callback's implementation for cdmi handlers.
%%% @end
%%%--------------------------------------------------------------------
-module(cdmi_existence_checker).
-author("<NAME>").

-include("global_definitions.hrl").
-include_lib("ctool/include/posix/file_attr.hrl").
-include_lib("ctool/include/posix/errors.hrl").
-include("modules/http_worker/rest/http_status.hrl").

%% API
-export([container_resource_exists/2, object_resource_exists/2]).

%%%===================================================================
%%% API
%%%===================================================================

%%--------------------------------------------------------------------
%% @doc @equiv pre_handler:resource_exists/2
%%--------------------------------------------------------------------
-spec container_resource_exists(cowboy_req:req(), #{}) -> {boolean(), cowboy_req:req(), #{}}.
container_resource_exists(Req, State) ->
    resource_exists(Req, State, container).


%%--------------------------------------------------------------------
%% @doc @equiv pre_handler:resource_exists/2
%%--------------------------------------------------------------------
-spec object_resource_exists(cowboy_req:req(), #{}) -> {boolean(), cowboy_req:req(), #{}}.
object_resource_exists(Req, State) ->
    resource_exists(Req, State, object).


%%%===================================================================
%%% Internal functions
%%%===================================================================

%%--------------------------------------------------------------------
%% @doc
%% Redirect this request to the same url but without trailing '/'.
%% @end
%%--------------------------------------------------------------------
-spec redirect_to_object(cowboy_req:req(), #{}) -> {halt, cowboy_req:req(), #{}}.
redirect_to_object(Req, #{path := Path} = State) ->
    redirect_to(Req, State, <<Path/binary, "/">>).

%%--------------------------------------------------------------------
%% @doc
%% Redirect this request to the same url but with trailing '/'.
%% @end
%%--------------------------------------------------------------------
-spec redirect_to_container(cowboy_req:req(), #{}) -> {halt, cowboy_req:req(), #{}}.
redirect_to_container(Req, #{path := Path} = State) ->
    redirect_to(Req, State, binary_part(Path, {0, byte_size(Path) - 1})).

%%--------------------------------------------------------------------<commit_msg>VFS-1402 - bugfix in cdmi_existence_checker<commit_after>%%%--------------------------------------------------------------------
%%% @author <NAME>
%%% @copyright (C) 2015 ACK CYFRONET AGH
%%% This software is released under the MIT license
%%% cited in 'LICENSE.txt'.
%%% @end
%%%--------------------------------------------------------------------
%%% @doc
%%% Common cowboy callback's implementation for cdmi handlers.
%%% @end
%%%--------------------------------------------------------------------
-module(cdmi_existence_checker).
-author("<NAME>").

-include("global_definitions.hrl").
-include_lib("ctool/include/posix/file_attr.hrl").
-include_lib("ctool/include/posix/errors.hrl").
-include("modules/http_worker/rest/http_status.hrl").

%% API
-export([container_resource_exists/2, object_resource_exists/2]).

%%%===================================================================
%%% API
%%%===================================================================

%%--------------------------------------------------------------------
%% @doc @equiv pre_handler:resource_exists/2
%%--------------------------------------------------------------------
-spec container_resource_exists(cowboy_req:req(), #{}) -> {boolean(), cowboy_req:req(), #{}}.
container_resource_exists(Req, State) ->
    resource_exists(Req, State, container).


%%--------------------------------------------------------------------
%% @doc @equiv pre_handler:resource_exists/2
%%--------------------------------------------------------------------
-spec object_resource_exists(cowboy_req:req(), #{}) -> {boolean(), cowboy_req:req(), #{}}.
object_resource_exists(Req, State) ->
    resource_exists(Req, State, object).


%%%===================================================================
%%% Internal functions
%%%===================================================================

%%--------------------------------------------------------------------
%% @doc
%% Redirect this request to the same url but without trailing '/'.
%% @end
%%--------------------------------------------------------------------
-spec redirect_to_object(cowboy_req:req(), #{}) -> {halt, cowboy_req:req(), #{}}.
redirect_to_object(Req, #{path := Path} = State) ->
    redirect_to(Req, State, binary_part(Path, {0, byte_size(Path) - 1})).

%%--------------------------------------------------------------------
%% @doc
%% Redirect this request to the same url but with trailing '/'.
%% @end
%%--------------------------------------------------------------------
-spec redirect_to_container(cowboy_req:req(), #{}) -> {halt, cowboy_req:req(), #{}}.
redirect_to_container(Req, #{path := Path} = State) ->
    redirect_to(Req, State, <<Path/binary, "/">>).

%%--------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.5182508131550415, 'fraction_numerical': 0.0043368268883267076, 'mean_word_length': 1.5636868920796665, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1464883', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1223, 'n_words': 233}