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

Commit

Permalink
ensure we truncate on eof when loading main file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Newson committed Mar 14, 2011
1 parent 64e2e29 commit 520cff7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/monic_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,27 @@ load_main_items(Tid, Fd, Location) ->
{ok, FooterSize, _} ->
load_main_items(Tid, Fd, Location + HeaderSize + Size + FooterSize);
eof ->
truncate(Fd, Location),
{ok, Location}
end;
eof ->
truncate(Fd, Location),
{ok, Location};
Else ->
Else
end.

abandon_write(#state{main_fd=Fd, reset_pos=Pos}=State) ->
truncate(Fd, Pos),
State#state{write_pos=Pos, writer=nil}.

truncate(Fd, Pos) ->
case file:position(Fd, Pos) of
{ok, Pos} ->
file:truncate(Fd);
_ ->
ok
end,
State#state{write_pos=Pos, writer=nil}.
file:position(Fd, Pos);
Else ->
Else
end.

stream_in(Pid, Ref, StreamBody) ->
case gen_server:call(Pid, {write, Ref, StreamBody}, infinity) of
Expand Down

0 comments on commit 520cff7

Please sign in to comment.