From ddac01338683fec071bd4beb8facfc274ae458d9 Mon Sep 17 00:00:00 2001 From: Anil Madhavapeddy Date: Tue, 13 Jan 2026 07:40:35 +0000 Subject: [PATCH] do not leak eio exceptiosn for find_file_in_dirs --- lib/xdge.ml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/xdge.ml b/lib/xdge.ml index 83be481..7da7151 100644 --- a/lib/xdge.ml +++ b/lib/xdge.ml @@ -236,6 +236,12 @@ let runtime_dir t = t.runtime_dir let config_dirs t = t.config_dirs let data_dirs t = t.data_dirs +(* Check if an Eio exception indicates a missing file/directory *) +let is_not_found_error = function + | Eio.Io (Eio.Fs.E (Eio.Fs.Not_found _), _) -> true + | Eio.Io (Eio.Fs.E (Eio.Fs.Permission_denied _), _) -> true + | _ -> false + (* File search following XDG specification *) let find_file_in_dirs dirs filename = let rec search_dirs = function @@ -246,7 +252,7 @@ let find_file_in_dirs dirs filename = (* Try to check if file exists and is readable *) let _ = Eio.Path.stat ~follow:true file_path in Some file_path - with _ -> + with exn when is_not_found_error exn -> (* File is inaccessible (non-existent, permissions, etc.) Skip and continue with next directory per XDG spec *) search_dirs remaining_dirs) -- 2.51.2