diff options
author | Micael Karlberg <[email protected]> | 2013-05-23 17:03:17 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2013-05-23 17:03:17 +0200 |
commit | 2fa265b38aeac7c4f29a878af6a7d3c49fe50931 (patch) | |
tree | c9fadea923d014846402983700bb8a090443a795 /lib/snmp/src/agent | |
parent | 38472ca2c30906d55dc0bee8f9fc2ed97b8576f3 (diff) | |
download | otp-2fa265b38aeac7c4f29a878af6a7d3c49fe50931.tar.gz otp-2fa265b38aeac7c4f29a878af6a7d3c49fe50931.tar.bz2 otp-2fa265b38aeac7c4f29a878af6a7d3c49fe50931.zip |
[snmp/agent] Handle mib-storage ets module non-ex file
Make sure snmpa_mib_storage_ets can handle a non-ex file
whe n openning a table (it should simply create it).
Diffstat (limited to 'lib/snmp/src/agent')
-rw-r--r-- | lib/snmp/src/agent/snmpa_mib_storage_ets.erl | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/snmp/src/agent/snmpa_mib_storage_ets.erl b/lib/snmp/src/agent/snmpa_mib_storage_ets.erl index 4afdc76ee5..852df06fa0 100644 --- a/lib/snmp/src/agent/snmpa_mib_storage_ets.erl +++ b/lib/snmp/src/agent/snmpa_mib_storage_ets.erl @@ -73,19 +73,29 @@ open(Name, RecName, _Fields, Type, Opts) -> {value, {dir, Dir}} -> Action = snmp_misc:get_option(action, Opts, keep), Checksum = snmp_misc:get_option(checksum, Opts, false), - ?vtrace("open ~p database ~p", [Type, Name]), + ?vtrace("open ~p database ~p - check if file exist", [Type, Name]), File = filename:join(Dir, atom_to_list(Name) ++ ".db"), case file:read_file_info(File) of {ok, _} -> + ?vdebug("open ~p database ~p - file exist - try reading", + [Type, Name]), case ets:file2tab(File, [{verify, Checksum}]) of {ok, ID} -> + ?vtrace("open ~p database ~p - " + "data read from file", [Type, Name]), {ok, #tab{id = ID, rec_name = RecName, file = File, checksum = Checksum}}; {error, Reason} when (Action =:= keep) -> + ?vinfo("open ~p database ~p - " + "failed reading from file (keep)", + [Type, Name, Reason]), {error, {file2tab, Reason}}; {error, Reason} -> + ?vlog("open ~p database ~p - " + "failed reading from file (clear)", + [Type, Name, Reason]), user_err("Warning: could not read file - " "create new (empty): " "~n File: ~p" @@ -97,9 +107,26 @@ open(Name, RecName, _Fields, Type, Opts) -> file = File, checksum = Checksum}} end; + {error, enoent} -> + %% No such file - create it + ?vdebug("open ~p database ~p - " + "file does *not* exist - create", + [Type, Name]), + ID = ets:new(Name, [Type, protected, {keypos, 2}]), + write_ets_file(ID, File, Checksum), + {ok, #tab{id = ID, + rec_name = RecName, + file = File, + checksum = Checksum}}; {error, Reason} when (Action =:= keep) -> + ?vinfo("open ~p database ~p - " + "failed reading file info (keep)", + [Type, Name, Reason]), {error, {read_file_info, Reason}}; {error, Reason} -> + ?vlog("open ~p database ~p - " + "failed reading file info (clear)", + [Type, Name, Reason]), user_err("Warning: could not read file info - " "create new: " "~n File: ~p" @@ -112,6 +139,7 @@ open(Name, RecName, _Fields, Type, Opts) -> checksum = Checksum}} end; false -> + ?vdebug("open ~p database ~p - ok", [Type, Name]), ID = ets:new(Name, [Type, protected, {keypos, 2}]), {ok, #tab{id = ID, rec_name = RecName}} end. |