fix(http_of_dir): handle bad symlinks

close #6
This commit is contained in:
Simon Cruanes 2019-11-19 18:27:32 -06:00
parent f548041263
commit cac954f10a

View file

@ -48,8 +48,13 @@ let html_list_dir ~top ~parent d : string =
Array.iter Array.iter
(fun f -> (fun f ->
if not @@ contains_dot_dot (d // f) then ( if not @@ contains_dot_dot (d // f) then (
Printf.bprintf body " <li> <a href=\"/%s\"> %s %s </a> </li>\n" let fpath = top // d // f in
(d // f) f (if Sys.is_directory (top // d // f) then "[dir]" else ""); if not @@ Sys.file_exists fpath then (
Printf.bprintf body " <li> %s [invalid file]</li>\n" f
) else (
Printf.bprintf body " <li> <a href=\"/%s\"> %s %s </a> </li>\n"
(d // f) f (if Sys.is_directory fpath then "[dir]" else "")
);
) )
) )
entries; entries;