From d79c08a5930b023596d640f6a42c0ec62938dd6d Mon Sep 17 00:00:00 2001 From: Volker Diels-Grabsch Date: Sat, 28 Feb 2026 00:20:41 +0100 Subject: [PATCH] Add missing_ok to Eio.Path.unlink (#828) --- lib_eio/path.ml | 6 ++++-- lib_eio/path.mli | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib_eio/path.ml b/lib_eio/path.ml index 37cd5ff09..184988ee3 100644 --- a/lib_eio/path.ml +++ b/lib_eio/path.ml @@ -160,11 +160,13 @@ let save ?append ~create path data = with_open_out ?append ~create path @@ fun flow -> Flow.copy_string data flow -let unlink t = +let unlink ?(missing_ok=false) t = let (Resource.T (dir, ops), path) = t in let module X = (val (Resource.get ops Fs.Pi.Dir)) in try X.unlink dir path - with Exn.Io _ as ex -> + with + | Exn.Io (Fs.(E (Not_found _)), _) when missing_ok -> () + | Exn.Io _ as ex -> let bt = Printexc.get_raw_backtrace () in Exn.reraise_with_context ex bt "removing file %a" pp t diff --git a/lib_eio/path.mli b/lib_eio/path.mli index d147f5454..ca47c0300 100644 --- a/lib_eio/path.mli +++ b/lib_eio/path.mli @@ -183,9 +183,12 @@ val read_link : _ t -> string (** {1 Other} *) -val unlink : _ t -> unit +val unlink : ?missing_ok:bool -> _ t -> unit (** [unlink t] removes directory entry [t]. + @param missing_ok If [false] (the default), raise an {!Fs.Not_found} IO error if [t] doesn't exist. + If [true], do nothing if [t] is missing. + Note: this cannot be used to unlink directories. Use {!rmdir} for directories. *)