Skip to content

Commit c255083

Browse files
authored
Merge pull request #833 from m-click/unlink-missing-ok
Add missing_ok to Eio.Path.unlink (#828)
2 parents f1c49da + d79c08a commit c255083

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

lib_eio/path.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,13 @@ let save ?append ~create path data =
160160
with_open_out ?append ~create path @@ fun flow ->
161161
Flow.copy_string data flow
162162

163-
let unlink t =
163+
let unlink ?(missing_ok=false) t =
164164
let (Resource.T (dir, ops), path) = t in
165165
let module X = (val (Resource.get ops Fs.Pi.Dir)) in
166166
try X.unlink dir path
167-
with Exn.Io _ as ex ->
167+
with
168+
| Exn.Io (Fs.(E (Not_found _)), _) when missing_ok -> ()
169+
| Exn.Io _ as ex ->
168170
let bt = Printexc.get_raw_backtrace () in
169171
Exn.reraise_with_context ex bt "removing file %a" pp t
170172

lib_eio/path.mli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,12 @@ val read_link : _ t -> string
183183

184184
(** {1 Other} *)
185185

186-
val unlink : _ t -> unit
186+
val unlink : ?missing_ok:bool -> _ t -> unit
187187
(** [unlink t] removes directory entry [t].
188188
189+
@param missing_ok If [false] (the default), raise an {!Fs.Not_found} IO error if [t] doesn't exist.
190+
If [true], do nothing if [t] is missing.
191+
189192
Note: this cannot be used to unlink directories.
190193
Use {!rmdir} for directories. *)
191194

0 commit comments

Comments
 (0)