mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
Merge pull request #28 from vbmithr/remove_safe
Added CCIO.remove_{exn,noerr} (thanks @vbmithr).
This commit is contained in:
commit
7d1433c47f
2 changed files with 24 additions and 2 deletions
|
|
@ -194,6 +194,7 @@ let tee funs g () = match g() with
|
||||||
*)
|
*)
|
||||||
|
|
||||||
module File = struct
|
module File = struct
|
||||||
|
type 'a or_error = [`Ok of 'a | `Error of string]
|
||||||
type t = string
|
type t = string
|
||||||
|
|
||||||
let to_string f = f
|
let to_string f = f
|
||||||
|
|
@ -207,7 +208,14 @@ module File = struct
|
||||||
|
|
||||||
let is_directory f = Sys.is_directory f
|
let is_directory f = Sys.is_directory f
|
||||||
|
|
||||||
let remove f = Sys.remove f
|
let remove_exn f = Sys.remove f
|
||||||
|
|
||||||
|
let remove f =
|
||||||
|
try `Ok (Sys.remove f)
|
||||||
|
with exn ->
|
||||||
|
`Error (Printexc.to_string exn)
|
||||||
|
|
||||||
|
let remove_noerr f = try Sys.remove f with _ -> ()
|
||||||
|
|
||||||
let read_dir_base d =
|
let read_dir_base d =
|
||||||
if Sys.is_directory d
|
if Sys.is_directory d
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,7 @@ See {!File.walk} if you also need to list directories:
|
||||||
*)
|
*)
|
||||||
|
|
||||||
module File : sig
|
module File : sig
|
||||||
|
type 'a or_error = [`Ok of 'a | `Error of string]
|
||||||
type t = string
|
type t = string
|
||||||
(** A file is always represented by its absolute path *)
|
(** A file is always represented by its absolute path *)
|
||||||
|
|
||||||
|
|
@ -146,7 +147,20 @@ module File : sig
|
||||||
|
|
||||||
val is_directory : t -> bool
|
val is_directory : t -> bool
|
||||||
|
|
||||||
val remove : t -> unit
|
val remove_exn : t -> unit
|
||||||
|
(** [remove_exn path] tries to remove the file at [path] from the
|
||||||
|
file system.
|
||||||
|
|
||||||
|
{b Raises} [Sys_error] if there is no file at [path].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val remove : t -> unit or_error
|
||||||
|
(** Like [remove_exn] but with an error monad.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val remove_noerr : t -> unit
|
||||||
|
(** Like [remove_exn] but do not raise any exception on failure.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val read_dir : ?recurse:bool -> t -> t gen
|
val read_dir : ?recurse:bool -> t -> t gen
|
||||||
(** [read_dir d] returns a sequence of files and directory contained
|
(** [read_dir d] returns a sequence of files and directory contained
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue