From cac954f10a0a6523a3e4537c291e2dbe88c4453d Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 19 Nov 2019 18:27:32 -0600 Subject: [PATCH] fix(http_of_dir): handle bad symlinks close #6 --- src/bin/http_of_dir.ml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bin/http_of_dir.ml b/src/bin/http_of_dir.ml index 66236a24..3acad633 100644 --- a/src/bin/http_of_dir.ml +++ b/src/bin/http_of_dir.ml @@ -48,8 +48,13 @@ let html_list_dir ~top ~parent d : string = Array.iter (fun f -> if not @@ contains_dot_dot (d // f) then ( - Printf.bprintf body "
  • %s %s
  • \n" - (d // f) f (if Sys.is_directory (top // d // f) then "[dir]" else ""); + let fpath = top // d // f in + if not @@ Sys.file_exists fpath then ( + Printf.bprintf body "
  • %s [invalid file]
  • \n" f + ) else ( + Printf.bprintf body "
  • %s %s
  • \n" + (d // f) f (if Sys.is_directory fpath then "[dir]" else "") + ); ) ) entries;