Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib_eio/path.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion lib_eio/path.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)

Expand Down