diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2010-08-22 19:01:54 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2010-08-22 19:01:54 +0100 |
commit | d8a85afe4c26e7c6b6660daa88b468fc6ef20760 (patch) | |
tree | 814133377361418548e055d3a3f4f539b5b1ada9 | |
parent | 8c3e7fe272cb84f066ade2906dc8ff453d6f5024 (diff) | |
download | rabbitmq-server-d8a85afe4c26e7c6b6660daa88b468fc6ef20760.tar.gz |
refactor: move open1 into reopen
-rw-r--r-- | src/file_handle_cache.erl | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/src/file_handle_cache.erl b/src/file_handle_cache.erl index 949cdc5e..d7ced819 100644 --- a/src/file_handle_cache.erl +++ b/src/file_handle_cache.erl @@ -560,12 +560,25 @@ sort_handles([{Ref, _} | RefHdls], RefHdlsA, [{Ref, Handle} | RefHdlsB], Acc) -> reopen([], Tree, RefHdls) -> put_age_tree(Tree), {ok, lists:reverse(RefHdls)}; -reopen([{Ref, NewOrReopen, Handle} | RefNewOrReopenHdls], Tree, RefHdls) -> - Now = now(), - case open1(Ref, Handle #handle { last_used_at = Now }, NewOrReopen) of - {ok, #handle {} = Handle1} -> +reopen([{Ref, NewOrReopen, Handle = #handle { hdl = closed, + path = Path, + mode = Mode, + offset = Offset }} | + RefNewOrReopenHdls], Tree, RefHdls) -> + case file:open(Path, case NewOrReopen of + new -> Mode; + reopen -> [read | Mode] + end) of + {ok, Hdl} -> + Now = now(), + {{ok, Offset1}, Handle1} = + maybe_seek(Offset, Handle #handle { hdl = Hdl, + offset = 0, + last_used_at = Now }), + Handle2 = Handle1 #handle { trusted_offset = Offset1 }, + put({Ref, fhc_handle}, Handle2), reopen(RefNewOrReopenHdls, gb_trees:insert(Now, Ref, Tree), - [{Ref, Handle1} | RefHdls]); + [{Ref, Handle2} | RefHdls]); {error, Reason} -> put_age_tree(Tree), [age_tree_delete(Handle1 #handle.last_used_at) || @@ -656,23 +669,6 @@ new_closed_handle(Path, Mode, Options) -> last_used_at = undefined }), {ok, Ref}. -open1(Ref, #handle { hdl = closed, path = Path, mode = Mode, offset = Offset } = - Handle, NewOrReopen) -> - Mode1 = case NewOrReopen of - new -> Mode; - reopen -> [read | Mode] - end, - case file:open(Path, Mode1) of - {ok, Hdl} -> - {{ok, Offset1}, Handle1} = - maybe_seek(Offset, Handle #handle { hdl = Hdl, offset = 0 }), - Handle2 = Handle1 #handle { trusted_offset = Offset1 }, - put({Ref, fhc_handle}, Handle2), - {ok, Handle2}; - {error, Reason} -> - {error, Reason} - end. - soft_close(Ref, Handle) -> {Res, Handle1} = soft_close(Handle), case Res of |