Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
don't close monic_file gen_servers now that they close themselves.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Newson committed Mar 11, 2011
1 parent d6307d9 commit 2099570
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
24 changes: 10 additions & 14 deletions src/monic_file_resource.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,16 @@ create_file(ReqData, Context) ->
add_item(ReqData, Context) ->
case monic_file:open(monic_utils:path(ReqData, Context)) of
{ok, Pid} ->
try
Size = list_to_integer(wrq:get_req_header("Content-Length", ReqData)),
StreamBody = wrq:stream_req_body(ReqData, ?BUFFER_SIZE),
case monic_file:add(Pid, Size, StreamBody) of
{ok, {Key, Cookie}} ->
File = wrq:path_info(file, ReqData),
Location = io_lib:format("/~s/~B/~B",[File, Key, Cookie]),
ReqData1 = wrq:set_resp_header("Location", Location, ReqData),
{true, ReqData1, Context};
_ ->
{false, ReqData, Context}
end
after
monic_file:close(Pid)
Size = list_to_integer(wrq:get_req_header("Content-Length", ReqData)),
StreamBody = wrq:stream_req_body(ReqData, ?BUFFER_SIZE),
case monic_file:add(Pid, Size, StreamBody) of
{ok, {Key, Cookie}} ->
File = wrq:path_info(file, ReqData),
Location = io_lib:format("/~s/~B/~B",[File, Key, Cookie]),
ReqData1 = wrq:set_resp_header("Location", Location, ReqData),
{true, ReqData1, Context};
_ ->
{false, ReqData, Context}
end;
_ ->
{false, ReqData, Context}
Expand Down
22 changes: 7 additions & 15 deletions src/monic_item_resource.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ resource_exists(ReqData, Context) ->
Cookie = list_to_integer(wrq:path_info(cookie, ReqData)),
Exists = case monic_file:open(monic_utils:path(ReqData, Context)) of
{ok, Pid} ->
try
case monic_file:info(Pid, Key, Cookie) of
{ok, _} ->
true;
{error, not_found} ->
false
end
after
monic_file:close(Pid)
case monic_file:info(Pid, Key, Cookie) of
{ok, _} ->
true;
{error, not_found} ->
false
end;
_ ->
false
Expand All @@ -57,12 +53,8 @@ fetch(ReqData, Context) ->
Cookie = list_to_integer(wrq:path_info(cookie, ReqData)),
case monic_file:open(Path) of
{ok, Pid} ->
try
{ok, StreamBody} = monic_file:read(Pid, Key, Cookie),
{{stream, StreamBody}, ReqData, Context}
after
monic_file:close(Pid)
end;
{ok, StreamBody} = monic_file:read(Pid, Key, Cookie),
{{stream, StreamBody}, ReqData, Context};
_ ->
{<<>>, ReqData, Context}
end.

0 comments on commit 2099570

Please sign in to comment.