File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1293,23 +1293,30 @@ defmodule File do
12931293 { :ok , files } ->
12941294 case mkdir ( dest ) do
12951295 success when success in [ :ok , { :error , :eexist } ] ->
1296- case copy_file_mode ( src , dest ) do
1297- :ok ->
1298- Enum . reduce_while ( files , [ dest | acc ] , fn x , acc ->
1299- case do_cp_r (
1300- Path . join ( src , x ) ,
1301- Path . join ( dest , x ) ,
1302- on_conflict ,
1303- dereference ,
1304- acc
1305- ) do
1306- { :error , _ , _ } = error -> { :halt , error }
1307- acc -> { :cont , acc }
1308- end
1309- end )
1310-
1311- { :error , reason } ->
1312- { :error , reason , src }
1296+ files
1297+ |> Enum . reduce_while ( [ dest | acc ] , fn x , acc ->
1298+ case do_cp_r (
1299+ Path . join ( src , x ) ,
1300+ Path . join ( dest , x ) ,
1301+ on_conflict ,
1302+ dereference ,
1303+ acc
1304+ ) do
1305+ { :error , _ , _ } = error -> { :halt , error }
1306+ acc -> { :cont , acc }
1307+ end
1308+ end )
1309+ |> case do
1310+ { :error , _ , _ } = error ->
1311+ error
1312+
1313+ files ->
1314+ # Change the directory after writing files in case
1315+ # it was originally read only
1316+ case copy_file_mode ( src , dest ) do
1317+ :ok -> files
1318+ { :error , reason } -> { :error , reason , src }
1319+ end
13131320 end
13141321
13151322 { :error , reason } ->
Original file line number Diff line number Diff line change @@ -875,15 +875,20 @@ defmodule FileTest do
875875 inner = Path . join ( src , "inner" )
876876
877877 File . mkdir_p! ( inner )
878- File . chmod! ( inner , 0o700 )
878+ File . write! ( Path . join ( inner , "hello" ) , "world" )
879+ File . chmod! ( inner , 0o500 )
879880
880881 try do
881882 File . cp_r! ( src , dest )
882883
883884 % File.Stat { mode: src_mode } = File . stat! ( inner )
884885 % File.Stat { mode: dest_mode } = File . stat! ( Path . join ( dest , "inner" ) )
885886 assert src_mode == dest_mode
887+
888+ assert File . read! ( Path . join ( dest , "inner/hello" ) ) == "world"
886889 after
890+ File . chmod! ( inner , 0o700 )
891+ File . chmod! ( Path . join ( dest , "inner" ) , 0o700 )
887892 File . rm_rf! ( src )
888893 File . rm_rf! ( dest )
889894 end
You can’t perform that action at this time.
0 commit comments