diff options
author | Vance Shipley <[email protected]> | 2017-07-07 12:47:03 +0530 |
---|---|---|
committer | Vance Shipley <[email protected]> | 2017-07-10 10:54:29 +0530 |
commit | c6340153528c3a3c7dc348bf33f1bdc12c9627dd (patch) | |
tree | 594c922ddd7124d35341c9e12bf9682f9d505e7e /lib/inets/src | |
parent | 0e9e2dadbee5dfcd78fb63a0120961a3782fe9a7 (diff) | |
download | otp-c6340153528c3a3c7dc348bf33f1bdc12c9627dd.tar.gz otp-c6340153528c3a3c7dc348bf33f1bdc12c9627dd.tar.bz2 otp-c6340153528c3a3c7dc348bf33f1bdc12c9627dd.zip |
Don't truncate existing disk_logs.
An existing internal format disk_log will be repaired if possible.
If not possible a new log will be created. This is the behaviour
described in the documentation and code comments.
Diffstat (limited to 'lib/inets/src')
-rw-r--r-- | lib/inets/src/http_server/mod_disk_log.erl | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/inets/src/http_server/mod_disk_log.erl b/lib/inets/src/http_server/mod_disk_log.erl index 3be5f2dd74..2023546f01 100644 --- a/lib/inets/src/http_server/mod_disk_log.erl +++ b/lib/inets/src/http_server/mod_disk_log.erl @@ -363,17 +363,21 @@ create_disk_log(Filename, MaxBytes, MaxFiles, ConfigList) -> %%---------------------------------------------------------------------- open(Filename, MaxBytes, MaxFiles, internal) -> - Opts = [{format, internal}, {repair, truncate}], - open1(Filename, MaxBytes, MaxFiles, Opts); + Opt0 = {format, internal}, + Opts1 = [Opt0, {repair, true}], + Opts2 = [Opt0, {repair, truncate}], + open1(Filename, MaxBytes, MaxFiles, Opts1, Opts2); open(Filename, MaxBytes, MaxFiles, _) -> Opts = [{format, external}], - open1(Filename, MaxBytes, MaxFiles, Opts). + open1(Filename, MaxBytes, MaxFiles, Opts, Opts). -open1(Filename, MaxBytes, MaxFiles, Opts0) -> - Opts1 = [{name, Filename}, {file, Filename}, {type, wrap}] ++ Opts0, - case open2(Opts1, {MaxBytes, MaxFiles}) of +open1(Filename, MaxBytes, MaxFiles, Opts1, Opts2) -> + Opts0 = [{name, Filename}, {file, Filename}, {type, wrap}], + case open2(Opts0 ++ Opts1, Opts0 ++ Opts2, {MaxBytes, MaxFiles}) of {ok, LogDB} -> {ok, LogDB}; + {repaired, LogDB, {recovered, _}, {badbytes, _}} -> + {ok, LogDB}; {error, Reason} -> {error, ?NICE("Can't create " ++ Filename ++ @@ -382,11 +386,16 @@ open1(Filename, MaxBytes, MaxFiles, Opts0) -> {error, ?NICE("Can't create "++Filename)} end. -open2(Opts, Size) -> - case disk_log:open(Opts) of +open2(Opts1, Opts2, Size) -> + case disk_log:open(Opts1) of {error, {badarg, size}} -> %% File did not exist, add the size option and try again - disk_log:open([{size, Size} | Opts]); + disk_log:open([{size, Size} | Opts1]); + {error, {Reason, _}} when + Reason == not_a_log_file; + Reason == invalid_index_file -> + %% File was corrupt, add the truncate option and try again + disk_log:open([{size, Size} | Opts2]); Else -> Else end. |