diff options
author | Hans Bolinder <[email protected]> | 2014-03-05 14:14:00 +0100 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2014-03-05 15:05:58 +0100 |
commit | e936ccec462760c4bb98679f1b88a7a5a3ead65f (patch) | |
tree | b6d42db19f3768b2e1a2c3818bad34c72eacf13b /lib/stdlib/src | |
parent | f02afa352f14e2dc0f3be4f6854a68b14129c2ba (diff) | |
download | otp-e936ccec462760c4bb98679f1b88a7a5a3ead65f.tar.gz otp-e936ccec462760c4bb98679f1b88a7a5a3ead65f.tar.bz2 otp-e936ccec462760c4bb98679f1b88a7a5a3ead65f.zip |
stdlib: Fix a Dets bug where files were deleted
Instead of deleting the small file when opening it with
dets:open_file/2 an error message is returned, mimicking the behaviour
when the file is bigger.
open_file/1 has been modified to return the same error message when
the file is small as when the file is bigger.
Thanks to Hakan Mattson for reporting this bug.
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r-- | lib/stdlib/src/dets.erl | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/stdlib/src/dets.erl b/lib/stdlib/src/dets.erl index 8c5c86f3b9..c32da1624f 100644 --- a/lib/stdlib/src/dets.erl +++ b/lib/stdlib/src/dets.erl @@ -2114,6 +2114,8 @@ test_bchunk_format(Head, Term) -> do_open_file([Fname, Verbose], Parent, Server, Ref) -> case catch fopen2(Fname, Ref) of + {error, {tooshort, _}} -> + err({error, {not_a_dets_file, Fname}}); {error, _Reason} = Error -> err(Error); {ok, Head} -> @@ -2127,11 +2129,10 @@ do_open_file([Fname, Verbose], Parent, Server, Ref) -> [Bad]), {error, {dets_bug, Fname, Bad}} end; -do_open_file([Tab, OpenArgs, Verb], Parent, Server, Ref) -> +do_open_file([Tab, OpenArgs, Verb], Parent, Server, _Ref) -> case catch fopen3(Tab, OpenArgs) of {error, {tooshort, _}} -> - _ = file:delete(OpenArgs#open_args.file), - do_open_file([Tab, OpenArgs, Verb], Parent, Server, Ref); + err({error, {not_a_dets_file, OpenArgs#open_args.file}}); {error, _Reason} = Error -> err(Error); {ok, Head} -> @@ -2487,7 +2488,6 @@ fopen2(Fname, Tab) -> {ok, _} -> Acc = read_write, Ram = false, - %% Fd is not always closed upon error, but exit is soon called. {ok, Fd, FH} = read_file_header(Fname, Acc, Ram), Mod = FH#fileheader.mod, Do = case Mod:check_file_header(FH, Fd) of @@ -2543,7 +2543,6 @@ fopen_existing_file(Tab, OpenArgs) -> ram_file = Ram, delayed_write = CacheSz, auto_save = Auto, access = Acc, version = Version, debug = Debug} = OpenArgs, - %% Fd is not always closed upon error, but exit is soon called. {ok, Fd, FH} = read_file_header(Fname, Acc, Ram), V9 = (Version =:= 9) or (Version =:= default), MinF = (MinSlots =:= default) or (MinSlots =:= FH#fileheader.min_no_slots), |