Skip to content

Commit 202e607

Browse files
authored
refactor(pkg): simplify polling code (#9648)
Signed-off-by: Rudi Grinberg <[email protected]>
1 parent 0e6f945 commit 202e607

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/dune_pkg/sys_poll.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
open Import
22
open Fiber.O
33

4+
let apply_or_skip_empty f = function
5+
| None | Some "" -> None
6+
| Some s -> Some (f s)
7+
;;
8+
49
let norm = function
510
| "" -> None
611
| s -> Some (String.lowercase s)
@@ -53,18 +58,14 @@ let arch ~path =
5358
| Intel -> Some "x86_32"
5459
| Unknown -> None)
5560
| _ -> Fiber.return None)
56-
>>| function
57-
| None | Some "" -> None
58-
| Some a -> Some (normalise_arch a)
61+
>>| apply_or_skip_empty normalise_arch
5962
;;
6063

6164
let os ~path =
6265
(match Sys.os_type with
6366
| "Unix" -> uname ~path [ "-s" ]
6467
| s -> Fiber.return (norm s))
65-
>>| function
66-
| None | Some "" -> None
67-
| Some s -> Some (normalise_os s)
68+
>>| apply_or_skip_empty normalise_os
6869
;;
6970

7071
let android_release ~path =
@@ -174,6 +175,8 @@ let os_distribution ~path =
174175
let os_family ~path =
175176
os ~path
176177
>>= function
178+
| Some ("freebsd" | "openbsd" | "netbsd" | "dragonfly") -> Fiber.return @@ Some "bsd"
179+
| Some ("win32" | "cygwin") -> Fiber.return @@ Some "windows"
177180
| Some "linux" ->
178181
os_release_field "ID_LIKE"
179182
>>= (function
@@ -183,8 +186,6 @@ let os_family ~path =
183186
(match Scanf.sscanf s " %s" Fun.id with
184187
| Error _ -> os_distribution ~path
185188
| Ok s -> Fiber.return @@ norm s))
186-
| Some ("freebsd" | "openbsd" | "netbsd" | "dragonfly") -> Fiber.return @@ Some "bsd"
187-
| Some ("win32" | "cygwin") -> Fiber.return @@ Some "windows"
188189
| _ -> os_distribution ~path
189190
;;
190191

0 commit comments

Comments
 (0)