mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
feat dir: only read content of regular files
no need to look into sockets, pipes, etc.
This commit is contained in:
parent
a39df1ba47
commit
e69f1b7c8c
1 changed files with 6 additions and 2 deletions
|
|
@ -94,8 +94,12 @@ let vfs_of_dir (top : string) : vfs =
|
||||||
let list_dir f = Sys.readdir (top // f)
|
let list_dir f = Sys.readdir (top // f)
|
||||||
|
|
||||||
let read_file_content f =
|
let read_file_content f =
|
||||||
let ic = Unix.(openfile (top // f) [ O_RDONLY ] 0) in
|
let fpath = top // f in
|
||||||
Tiny_httpd_stream.of_fd_close_noerr ic
|
match Unix.stat fpath with
|
||||||
|
| { st_kind = Unix.S_REG; _ } ->
|
||||||
|
let ic = Unix.(openfile fpath [ O_RDONLY ] 0) in
|
||||||
|
Tiny_httpd_stream.of_fd_close_noerr ic
|
||||||
|
| _ -> failwith (Printf.sprintf "not a regular file: %S" f)
|
||||||
|
|
||||||
let create f =
|
let create f =
|
||||||
let oc = open_out_bin (top // f) in
|
let oc = open_out_bin (top // f) in
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue