Skip to content

Commit

Permalink
Add pp_perm_hum to lib_main/test/eio_stat
Browse files Browse the repository at this point in the history
  • Loading branch information
patricoferris committed Aug 26, 2023
1 parent 7d041d2 commit 6f8d307
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib_main/tests/eio_stat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ let pp_time f t =
(tm.Unix.tm_year + 1900) (tm.Unix.tm_mon + 1) tm.Unix.tm_mday
tm.Unix.tm_hour tm.Unix.tm_min tm.Unix.tm_sec

let pp_perm_hum ppf v =
let rwx i = ((i land 4) = 4), ((i land 2) = 2), (i land 1 = 1) in
let pp_rwx ppf (r, w, x) =
let is_set c v = if v then c else "-" in
Format.fprintf ppf "%s%s%s" (is_set "r" r) (is_set "w" w) (is_set "x" x);
in
Format.fprintf ppf "%a%a%a" pp_rwx (rwx (v lsr 6)) pp_rwx (rwx (v lsr 3)) pp_rwx (rwx v)

let run_stat fs fname =
let open Eio in
let path = Path.(fs / fname) in
Expand All @@ -14,14 +22,16 @@ let run_stat fs fname =
| _ -> "" in
Path.stat ~follow:false path File.[Kind; Size; Dev; Ino; Nlink; Perm; Uid; Gid; Atime; Mtime; Ctime]
(fun kind size dev ino nlink perm uid gid atime mtime ctime ->
Format.printf " File: %s%s\n Size: %Lu\t\t %a\nDevice: %Lu\tInode: %Lu\tLinks: %Lu\nAccess: (%04o/TODO)\tUid: (%Lu/TODO)\tGid: (%Lu/TODO)\nAccess: %a\nModify: %a\nChange: %a\n%!"
Format.printf " File: %s%s\n Size: %Lu\t\tFileType: %a\nDevice: %Lu\tInode: %Lu\tLinks: %Lu\nMode: (%04o/-%a)\tUid: (%Lu/TODO)\tGid: (%Lu/TODO)\nAccess: %a\nModify: %a\nChange: %a\n%!"
fname (opt_symlink kind)
size
Eio.File.pp_kind kind
dev
ino
nlink
perm
pp_perm_hum
perm
uid
gid
pp_time atime
Expand Down

0 comments on commit 6f8d307

Please sign in to comment.