Skip to content

Commit

Permalink
kernel/file: Don't send delete_file/2 args to file server
Browse files Browse the repository at this point in the history
  • Loading branch information
jdamanalo committed May 11, 2023
1 parent b4230be commit 039a3bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/kernel/src/file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,14 @@ delete(Name) ->
Reason :: posix() | badarg.

delete(Name, Opts) when is_list(Opts) ->
Args = [file_name(Name), Opts],
case check_args(Args) of
FileName = file_name(Name),
case check_args(Opts) of
ok ->
case lists:member(raw, Opts) of
true ->
[FileName|_] = Args,
?PRIM_FILE:delete(FileName);
false ->
call(delete, Args)
call(delete, [FileName])
end;
Error ->
Error
Expand Down
17 changes: 17 additions & 0 deletions lib/kernel/test/file_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2339,6 +2339,23 @@ delete(Config) when is_list(Config) ->
{error, _} = ?FILE_MODULE:open(Name2, read),
%% Try deleting a nonexistent file with the raw option
{error, enoent} = ?FILE_MODULE:delete(Name2, [raw]),

Name3 = filename:join(RootDir,
atom_to_list(?MODULE)
++"_delete_3.fil"),
{ok, Fd5} = ?FILE_MODULE:open(Name3, write),
io:format(Fd5,"ok.\n",[]),
ok = ?FILE_MODULE:close(Fd5),
%% Check that the file is readable
{ok, Fd6} = ?FILE_MODULE:open(Name3, read),
ok = ?FILE_MODULE:close(Fd6),
%% Try deleting with no option, should be equivalent to delete/1
ok = ?FILE_MODULE:delete(Name3, []),
%% Check that the file is not readable anymore
{error, _} = ?FILE_MODULE:open(Name3, read),
%% Try deleting a nonexistent file with no option
{error, enoent} = ?FILE_MODULE:delete(Name3, []),

[] = flush(),
ok.

Expand Down

0 comments on commit 039a3bd

Please sign in to comment.