From 4f7ea8de647f80ab9fa1ed05ef0b2d90eb5bb972 Mon Sep 17 00:00:00 2001 From: Vincent Bernardoff Date: Sat, 27 Dec 2014 17:53:04 +0100 Subject: [PATCH 1/3] Added CCIO.remove_safe. --- src/io/CCIO.ml | 2 ++ src/io/CCIO.mli | 1 + 2 files changed, 3 insertions(+) diff --git a/src/io/CCIO.ml b/src/io/CCIO.ml index 61f64cbb..1a6e5a1a 100644 --- a/src/io/CCIO.ml +++ b/src/io/CCIO.ml @@ -209,6 +209,8 @@ module File = struct let remove f = Sys.remove f + let remove_safe f = try Sys.remove f with _ -> () + let read_dir_base d = if Sys.is_directory d then diff --git a/src/io/CCIO.mli b/src/io/CCIO.mli index 78180bac..b0a92432 100644 --- a/src/io/CCIO.mli +++ b/src/io/CCIO.mli @@ -147,6 +147,7 @@ module File : sig val is_directory : t -> bool val remove : t -> unit + val remove_safe : t -> unit val read_dir : ?recurse:bool -> t -> t gen (** [read_dir d] returns a sequence of files and directory contained From 4df8e2660c21e2d8ecd8bca8af1465179a73f6ba Mon Sep 17 00:00:00 2001 From: Vincent Bernardoff Date: Mon, 29 Dec 2014 17:11:23 +0100 Subject: [PATCH 2/3] Fix CCIO.remove* functions. --- src/io/CCIO.ml | 10 ++++++++-- src/io/CCIO.mli | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/io/CCIO.ml b/src/io/CCIO.ml index 1a6e5a1a..5f2916c8 100644 --- a/src/io/CCIO.ml +++ b/src/io/CCIO.ml @@ -194,6 +194,7 @@ let tee funs g () = match g() with *) module File = struct + type 'a or_error = [`Ok of 'a | `Error of string] type t = string let to_string f = f @@ -207,9 +208,14 @@ module File = struct let is_directory f = Sys.is_directory f - let remove f = Sys.remove f + let remove_exn f = Sys.remove f - let remove_safe f = try Sys.remove f with _ -> () + 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 = if Sys.is_directory d diff --git a/src/io/CCIO.mli b/src/io/CCIO.mli index b0a92432..945fb5ce 100644 --- a/src/io/CCIO.mli +++ b/src/io/CCIO.mli @@ -134,6 +134,7 @@ See {!File.walk} if you also need to list directories: *) module File : sig + type 'a or_error = [`Ok of 'a | `Error of string] type t = string (** A file is always represented by its absolute path *) @@ -146,8 +147,17 @@ module File : sig val is_directory : t -> bool - val remove : t -> unit - val remove_safe : 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] *) + + val remove : t -> unit or_error + (** Like [remove_exn] but with an error monad. *) + + val remove_noerr : t -> unit + (** Like [remove_exn] but do not raise any exception on failure. *) val read_dir : ?recurse:bool -> t -> t gen (** [read_dir d] returns a sequence of files and directory contained From 4f7e3015270a2bdb9f5984a849985ad2a6a99df2 Mon Sep 17 00:00:00 2001 From: Vincent Bernardoff Date: Mon, 29 Dec 2014 19:26:49 +0100 Subject: [PATCH 3/3] Added @since NEXT_RELEASE. --- src/io/CCIO.mli | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/io/CCIO.mli b/src/io/CCIO.mli index 945fb5ce..a7e43112 100644 --- a/src/io/CCIO.mli +++ b/src/io/CCIO.mli @@ -151,13 +151,16 @@ module File : sig (** [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] *) + {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. *) + (** 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. *) + (** Like [remove_exn] but do not raise any exception on failure. + @since NEXT_RELEASE *) val read_dir : ?recurse:bool -> t -> t gen (** [read_dir d] returns a sequence of files and directory contained