XDG library path support for OCaml via Eio capabilities
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

xdge: Extract parse_dir_list helper to eliminate duplication

+11 -16
+11 -16
lib/xdge.ml
··· 89 89 (* Helper to resolve system directories (config_dirs or data_dirs) *) 90 90 let resolve_system_dirs fs home_path app_name override_suffix xdg_var 91 91 default_paths = 92 + let parse_dir_list var dirs = 93 + String.split_on_char ':' dirs 94 + |> List.filter (fun s -> s <> "") 95 + |> List.filter_map (fun path -> 96 + try 97 + validate_absolute_path var path; 98 + Some Eio.Path.(resolve_path fs home_path path / app_name) 99 + with Invalid_xdg_path _ -> None) 100 + in 92 101 let override_var = make_env_var_name app_name override_suffix in 93 102 match Sys.getenv_opt override_var with 94 - | Some dirs when dirs <> "" -> 95 - String.split_on_char ':' dirs 96 - |> List.filter (fun s -> s <> "") 97 - |> List.filter_map (fun path -> 98 - try 99 - validate_absolute_path override_var path; 100 - Some Eio.Path.(resolve_path fs home_path path / app_name) 101 - with Invalid_xdg_path _ -> None) 103 + | Some dirs when dirs <> "" -> parse_dir_list override_var dirs 102 104 | Some _ | None -> ( 103 105 match Sys.getenv_opt xdg_var with 104 - | Some dirs when dirs <> "" -> 105 - String.split_on_char ':' dirs 106 - |> List.filter (fun s -> s <> "") 107 - |> List.filter_map (fun path -> 108 - try 109 - validate_absolute_path xdg_var path; 110 - Some Eio.Path.(resolve_path fs home_path path / app_name) 111 - with Invalid_xdg_path _ -> None) 106 + | Some dirs when dirs <> "" -> parse_dir_list xdg_var dirs 112 107 | Some _ | None -> 113 108 List.map 114 109 (fun path -> Eio.Path.(resolve_path fs home_path path / app_name))