Permalink
Browse files

Done IT leo-project/leofs#136

  • Loading branch information...
1 parent 63a1dbb commit c613f26c2beef547e37af469fdf39814f30f7a38 @mocchira mocchira committed Feb 13, 2014
Showing with 40 additions and 5 deletions.
  1. +2 −3 src/leo_gateway_http_commons.erl
  2. +1 −0 src/leo_gateway_large_object_handler.erl
  3. +37 −2 src/leo_gateway_s3_api.erl
View
5 src/leo_gateway_http_commons.erl
@@ -370,7 +370,7 @@ move_large_object_1({ok, Data},
handler = WriteHandler} = ReqLargeObj, ReadHandler) ->
case catch leo_gateway_large_object_handler:put(WriteHandler, Data) of
ok ->
- move_large_object_1(leo_gateway_large_object_handler:get_chunk(ReadHandler), ReqLargeObj, ReadHandler);
+ move_large_object_1(leo_gateway_large_object_handler:get_chunked(ReadHandler), ReqLargeObj, ReadHandler);
{'EXIT', Cause} ->
?error("move_large_object_1/3", "key:~s, cause:~p", [binary_to_list(Key), Cause]),
{error, ?ERROR_FAIL_PUT_OBJ};
@@ -379,8 +379,7 @@ move_large_object_1({ok, Data},
{error, ?ERROR_FAIL_PUT_OBJ}
end;
move_large_object_1({error, Cause},
- #req_large_obj{key = Key,
- handler = WriteHandler}, _) ->
+ #req_large_obj{key = Key}, _) ->
?error("move_large_object_1/3", "key:~s, cause:~p", [binary_to_list(Key), Cause]),
{error, ?ERROR_FAIL_RETRIEVE_OBJ};
move_large_object_1(done, #req_large_obj{handler = WriteHandler,
View
1 src/leo_gateway_large_object_handler.erl
@@ -36,6 +36,7 @@
%% Application callbacks
-export([start_link/1, start_link/2, start_link/3, stop/1]).
-export([put/2, get/4, get_chunked/1, rollback/1, result/1, state/1]).
+-export([delete_chunked_objects/2]).
-export([init/1,
handle_call/3,
handle_cast/2,
View
39 src/leo_gateway_s3_api.erl
@@ -230,7 +230,7 @@ put_object(?BIN_EMPTY, Req, Key, Params) ->
%% @doc POST/PUT operation on Objects. COPY/REPLACE
%% @private
-put_object(Directive, Req, Key, #req_params{handler = ?HTTP_HANDLER_S3}) ->
+put_object(Directive, Req, Key, #req_params{handler = ?HTTP_HANDLER_S3} = Params) ->
CS = ?http_header(Req, ?HTTP_HEAD_X_AMZ_COPY_SOURCE),
%% need to trim head '/' when cooperating with s3fs(-c)
@@ -242,8 +242,10 @@ put_object(Directive, Req, Key, #req_params{handler = ?HTTP_HANDLER_S3}) ->
end,
case leo_gateway_rpc_handler:get(CS2) of
- {ok, Meta, RespObject} ->
+ {ok, #metadata{cnumber = 0} = Meta, RespObject} ->
put_object_1(Directive, Req, Key, Meta, RespObject);
+ {ok, #metadata{cnumber = _TotalChunkedObjs} = Meta, _RespObject} ->
+ put_large_object_1(Directive, Req, Key, Meta, Params);
{error, not_found} ->
?reply_not_found([?SERVER_HEADER], Key, <<>>, Req);
{error, ?ERR_TYPE_INTERNAL_ERROR} ->
@@ -288,6 +290,39 @@ put_object_3(Req, Meta) ->
?reply_timeout([?SERVER_HEADER], Meta#metadata.key, <<>>, Req)
end.
+%% @doc POST/PUT operation on `Large` Objects. COPY
+%% @private
+put_large_object_1(Directive, Req, Key, Meta, Params) ->
+ case leo_gateway_http_commons:move_large_object(Meta, Key, Params) of
+ ok when Directive == ?HTTP_HEAD_X_AMZ_META_DIRECTIVE_COPY ->
+ resp_copy_obj_xml(Req, Meta);
+ ok when Directive == ?HTTP_HEAD_X_AMZ_META_DIRECTIVE_REPLACE ->
+ put_large_object_2(Req, Key, Meta);
+ {error, timeout} ->
+ ?reply_timeout([?SERVER_HEADER], Key, <<>>, Req);
+ {error, _Other} ->
+ ?reply_internal_error([?SERVER_HEADER], Key, <<>>, Req)
+ end.
+
+%% @doc POST/PUT operation on Objects. REPLACE
+%% @private
+put_large_object_2(Req, Key, Meta) ->
+ case Key == Meta#metadata.key of
+ true -> resp_copy_obj_xml(Req, Meta);
+ false -> put_large_object_3(Req, Meta)
+ end.
+
+put_large_object_3(Req, Meta) ->
+ case leo_gateway_large_object_handler:delete_chunked_objects(Meta#metadata.key, Meta#metadata.cnumber) of
+ ok ->
+ resp_copy_obj_xml(Req, Meta);
+ {error, not_found} ->
+ resp_copy_obj_xml(Req, Meta);
+ {error, ?ERR_TYPE_INTERNAL_ERROR} ->
+ ?reply_internal_error([?SERVER_HEADER], Meta#metadata.key, <<>>, Req);
+ {error, timeout} ->
+ ?reply_timeout([?SERVER_HEADER], Meta#metadata.key, <<>>, Req)
+ end.
%% @doc DELETE operation on Objects
-spec(delete_object(any(), binary(), #req_params{}) ->

0 comments on commit c613f26

Please sign in to comment.