Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mas i1847 conditionalput #410

Merged
merged 3 commits into from
Jan 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/riakc_obj.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
get_content_types/1,
get_value/1,
get_values/1,
get_vtag/1,
update_metadata/2,
update_value/2,
update_value/3,
Expand Down Expand Up @@ -226,6 +227,55 @@ get_metadata(O=#riakc_obj{}) ->
get_metadatas(#riakc_obj{contents=Contents}) ->
[M || {M,_V} <- Contents].

-spec get_vtag(riakc_obj()) -> binary().
get_vtag(Obj) ->
case get_metadatas(Obj) of
[M] ->
case dict:find(?MD_VTAG, M) of
{ok, Vtag} ->
Vtag;
_ ->
throw(no_vtag)
end;
_Ms ->
vclock_etag(Obj)
end.

-spec vclock_etag(riakc_obj()) -> string().
vclock_etag(Obj) ->
<<ETag:128/integer>>
= crypto:hash(
md5,
zlib:unzip(riakc_obj:vclock(Obj))),
"\"" ++ integer_to_base(ETag, 62) ++ "\"".

%% @doc based on riak_core_util:integer_to_list/2.
-spec integer_to_base(Integer :: integer(), Base :: integer()) -> string().
integer_to_base(I, Base)
when is_integer(I), is_integer(Base), Base >= 2, Base =< 62 ->
integer_to_base(I, Base, []).

-spec integer_to_base(integer(), integer(), string()) -> string().
integer_to_base(I0, Base, R0) ->
D = I0 rem Base,
I1 = I0 div Base,
R1 =
if
D >= 36 ->
[D-36+$a|R0];
D >= 10 ->
[D-10+$A|R0];
true ->
[D+$0|R0]
end,
if
I1 =:= 0 ->
R1;
true ->
integer_to_base(I1, Base, R1)
end.


%% @doc Return the content type of the value if there are no siblings.
%% @see get_metadata/1
%% @throws siblings
Expand Down