Skip to content

Commit

Permalink
Make OpamSystem.remove_file quiet when used in OpamSystem.remove_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed May 4, 2023
1 parent 7f295a9 commit a830fe5
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/core/opamSystem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ let win32_unlink fn =
Unix.unlink fn
with _ -> raise e)

let remove_file file =
let remove_file ~with_log file =
if
try ignore (Unix.lstat file); true with Unix.Unix_error _ -> false
then (
try
log "rm %s" file;
if with_log then
log "rm %s" file;
if Sys.win32 then
win32_unlink file
else
Expand All @@ -124,7 +125,7 @@ let rec remove_dir dir =
| {Unix.st_kind = Unix.S_DIR; _} ->
remove_dir file
| {Unix.st_kind = Unix.(S_REG | S_LNK | S_CHR | S_BLK | S_FIFO | S_SOCK); _} ->
remove_file file
remove_file ~with_log:false file
) files;
Unix.rmdir dir

Expand All @@ -134,9 +135,11 @@ let remove_dir dir =
if Sys.is_directory dir then
remove_dir dir
else
remove_file dir
remove_file ~with_log:false dir
end

let remove_file file = remove_file ~with_log:true file

let temp_files = Hashtbl.create 1024
let logs_cleaner =
let to_clean = ref OpamStd.String.Set.empty in
Expand Down Expand Up @@ -172,21 +175,6 @@ let rec temp_file ?(auto_clean=true) ?dir prefix =
file
)

let remove_file file =
if
try ignore (Unix.lstat file); true with Unix.Unix_error _ -> false
then (
log "rm %s" file;
try
try Unix.unlink file
with Unix.Unix_error(EACCES, _, _) when Sys.win32 ->
(* Attempt to remove the read-only bit on Windows *)
Unix.chmod file 0o666;
Unix.unlink file
with Unix.Unix_error _ as e ->
internal_error "Cannot remove %s (%s)." file (Printexc.to_string e)
)

let string_of_channel ic =
let n = 32768 in
let s = Bytes.create n in
Expand Down

0 comments on commit a830fe5

Please sign in to comment.