Skip to content

Commit 5cc2724

Browse files
committed
File.rm makes files writeable on Windows before deletion
1 parent 5158a19 commit 5cc2724

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/elixir/lib/file.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,15 @@ defmodule File do
765765
"""
766766
@spec rm(Path.t) :: :ok | {:error, posix}
767767
def rm(path) do
768+
if match? {:win32, _}, :os.type do
769+
case F.read_file_info(IO.chardata_to_string(path)) do
770+
{:ok, file_info} ->
771+
if elem(file_info, 3) in [:read, :none] do
772+
File.chmod(path, (elem(file_info, 7) + 128)) # 128 is octal mask 200 in decimal
773+
end
774+
{:error, reason} -> {:error, reason}
775+
end
776+
end
768777
F.delete(IO.chardata_to_string(path))
769778
end
770779

0 commit comments

Comments
 (0)