My aggregated monorepo of OCaml code, automaintained
0
fork

Configure Feed

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

Fix Sudo.rm_rf to fall back to sudo on any non-sudo failure

Previously used try/with which only caught Unix exceptions, missing
the case where Bos.OS.Path.delete returns Error (not an exception)
on root-owned files. This caused 3000+ temp dirs to leak because
cleanup silently failed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+6 -10
+6 -10
day11/exec/sudo.ml
··· 10 10 let rm_rf env path = 11 11 let path_s = Fpath.to_string path in 12 12 (* Try without sudo first *) 13 - try 14 - Bos.OS.Path.delete ~recurse:true path |> Result.map_error (fun (`Msg m) -> `Msg m) 15 - with 16 - | Unix.Unix_error ((Unix.EACCES | Unix.EPERM), _, _) -> 17 - Log.info (fun m -> m "Permission denied, retrying with sudo: %s" path_s); 18 - let cmd = Bos.Cmd.(v "rm" % "-rf" % path_s) in 19 - run env cmd |> Result.map (fun _run -> ()) 20 - | Unix.Unix_error (e, fn, arg) -> 21 - Rresult.R.error_msgf "rm_rf %s: %s(%s): %s" 22 - path_s fn arg (Unix.error_message e) 13 + match Bos.OS.Path.delete ~recurse:true path with 14 + | Ok () -> Ok () 15 + | Error _ -> 16 + (* Non-sudo failed (root-owned files, etc.) — use sudo *) 17 + let cmd = Bos.Cmd.(v "rm" % "-rf" % path_s) in 18 + run env cmd |> Result.map (fun _run -> ())