Add Sys.force_remove
Sys.force_remove is Sys.remove, except on Windows, where it will remove the "read-only" attribute and re-try a failed Sys.remove
This commit is contained in:
parent
8dd66ed3d8
commit
bf3fa0831d
|
@ -537,7 +537,7 @@ let rec exec t ~ectx ~dir ~env_extra ~stdout_to ~stderr_to =
|
||||||
return ()
|
return ()
|
||||||
| Create_file fn ->
|
| Create_file fn ->
|
||||||
let fn = Path.to_string fn in
|
let fn = Path.to_string fn in
|
||||||
if Sys.file_exists fn then Sys.remove fn;
|
if Sys.file_exists fn then Sys.force_remove fn;
|
||||||
Unix.close (Unix.openfile fn [O_CREAT; O_TRUNC; O_WRONLY] 0o666);
|
Unix.close (Unix.openfile fn [O_CREAT; O_TRUNC; O_WRONLY] 0o666);
|
||||||
return ()
|
return ()
|
||||||
| Copy (src, dst) ->
|
| Copy (src, dst) ->
|
||||||
|
|
|
@ -225,7 +225,7 @@ module Temp = struct
|
||||||
let fns = !tmp_files in
|
let fns = !tmp_files in
|
||||||
tmp_files := String_set.empty;
|
tmp_files := String_set.empty;
|
||||||
String_set.iter fns ~f:(fun fn ->
|
String_set.iter fns ~f:(fun fn ->
|
||||||
try Sys.remove fn with _ -> ()))
|
try Sys.force_remove fn with _ -> ()))
|
||||||
|
|
||||||
let create prefix suffix =
|
let create prefix suffix =
|
||||||
let fn = Filename.temp_file prefix suffix in
|
let fn = Filename.temp_file prefix suffix in
|
||||||
|
@ -233,7 +233,7 @@ module Temp = struct
|
||||||
fn
|
fn
|
||||||
|
|
||||||
let destroy fn =
|
let destroy fn =
|
||||||
Sys.remove fn;
|
Sys.force_remove fn;
|
||||||
tmp_files := String_set.remove fn !tmp_files
|
tmp_files := String_set.remove fn !tmp_files
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -293,6 +293,22 @@ module String = struct
|
||||||
loop 0 0 ~last_is_cr:false
|
loop 0 0 ~last_is_cr:false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Sys = struct
|
||||||
|
include Sys
|
||||||
|
|
||||||
|
let force_remove =
|
||||||
|
if win32 then
|
||||||
|
fun fn ->
|
||||||
|
try
|
||||||
|
remove fn
|
||||||
|
with Sys_error _ ->
|
||||||
|
(* Try to remove the "read-only" attribute, then retry. *)
|
||||||
|
(try Unix.chmod fn 0o666 with Unix.Unix_error _ -> ());
|
||||||
|
remove fn
|
||||||
|
else
|
||||||
|
remove
|
||||||
|
end
|
||||||
|
|
||||||
module Filename = struct
|
module Filename = struct
|
||||||
include Filename
|
include Filename
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue