Improve code for directory deletion

This commit is contained in:
Evgeny Khramtsov 2019-04-29 18:50:54 +03:00
parent a0f48cf52f
commit 1db22c9656
1 changed files with 2 additions and 6 deletions

View File

@ -975,9 +975,7 @@ remove_user(User, Server) ->
end, end,
ok. ok.
-spec del_tree(file:filename_all()) -> ok | {error, term()}. -spec del_tree(file:filename_all()) -> ok | {error, file:posix()}.
del_tree(Dir) when is_binary(Dir) ->
del_tree(binary_to_list(Dir));
del_tree(Dir) -> del_tree(Dir) ->
try try
{ok, Entries} = file:list_dir(Dir), {ok, Entries} = file:list_dir(Dir),
@ -988,11 +986,9 @@ del_tree(Dir) ->
false -> false ->
ok = file:delete(Path) ok = file:delete(Path)
end end
end, [Dir ++ "/" ++ Entry || Entry <- Entries]), end, [filename:join(Dir, Entry) || Entry <- Entries]),
ok = file:del_dir(Dir) ok = file:del_dir(Dir)
catch catch
_:{badmatch, {error, Error}} -> _:{badmatch, {error, Error}} ->
{error, Error};
_:Error ->
{error, Error} {error, Error}
end. end.