File bitcask-2.0.8-fileop.patch of Package bitcask
diff -Ndurp bitcask-2.0.8/src/bitcask.erl bitcask-2.0.8-fileop/src/bitcask.erl
--- bitcask-2.0.8/src/bitcask.erl 2017-03-04 01:37:58.000000000 +0200
+++ bitcask-2.0.8-fileop/src/bitcask.erl 2019-07-07 02:08:51.586710621 +0300
@@ -3081,11 +3081,6 @@ efile_error_test() ->
B = bitcask:open(Dir, [read_write]),
ok = bitcask:put(B, <<"k">>, <<"v">>),
ok = bitcask:close(B),
- Port = get(bitcask_efile_port),
- % If this fails, we stopped using the efile port trick to list
- % dir contents, so remove this test
- ?assert(is_port(Port)),
- true = erlang:port_close(Port),
case bitcask:open(Dir) of
{error, _} = Err ->
?assertEqual(ok, Err);
diff -Ndurp bitcask-2.0.8/src/bitcask_fileops.erl bitcask-2.0.8-fileop/src/bitcask_fileops.erl
--- bitcask-2.0.8/src/bitcask_fileops.erl 2017-03-04 01:37:58.000000000 +0200
+++ bitcask-2.0.8-fileop/src/bitcask_fileops.erl 2019-07-07 02:08:33.668130995 +0300
@@ -838,46 +838,7 @@ ensure_dir(F) ->
end.
list_dir(Dir) ->
- list_dir(Dir, 1).
-
-list_dir(_, 0) ->
- {error, efile_driver_unavailable};
-list_dir(Directory, Retries) when is_integer(Retries), Retries > 0 ->
- Port = get_efile_port(),
- case prim_file:list_dir(Port, Directory) of
- {error, einval} ->
- clear_efile_port(),
- list_dir(Directory, Retries-1);
- Result ->
- Result
- end.
-
-get_efile_port() ->
- Key = bitcask_efile_port,
- case get(Key) of
- undefined ->
- case prim_file_drv_open("efile", [binary]) of
- {ok, Port} ->
- put(Key, Port),
- get_efile_port();
- Err ->
- error_logger:error_msg("get_efile_port: ~p\n", [Err]),
- timer:sleep(1000),
- get_efile_port()
- end;
- Port ->
- Port
- end.
-
-clear_efile_port() ->
- erase(bitcask_efile_port).
-
-prim_file_drv_open(Driver, Portopts) ->
- try erlang:open_port({spawn, Driver}, Portopts) of
- Port ->
- {ok, Port}
- catch
- error:Reason ->
- {error, Reason}
+ case prim_file:list_dir(Dir) of
+ {ok, _} = Result -> Result;
+ _ -> {error, efile_driver_unavailable}
end.
-