File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -765,6 +765,15 @@ defmodule File do
765
765
"""
766
766
@ spec rm ( Path . t ) :: :ok | { :error , posix }
767
767
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 ) + 0200 ) )
773
+ end
774
+ { :error , reason } -> { :error , reason }
775
+ end
776
+ end
768
777
F . delete ( IO . chardata_to_string ( path ) )
769
778
end
770
779
Original file line number Diff line number Diff line change @@ -688,6 +688,15 @@ defmodule FileTest do
688
688
assert File . rm ( fixture ) == :ok
689
689
refute File . exists? ( fixture )
690
690
end
691
+
692
+ test :rm_read_only_file do
693
+ fixture = tmp_path ( "tmp_test.txt" )
694
+ File . write ( fixture , "test" )
695
+ assert File . exists? ( fixture )
696
+ File . chmod ( fixture , 0100444 )
697
+ assert File . rm ( fixture ) == :ok
698
+ refute File . exists? ( fixture )
699
+ end
691
700
692
701
test :rm_file_with_dir do
693
702
assert File . rm ( fixture_path ) == { :error , :eperm }
You can’t perform that action at this time.
0 commit comments