1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors combinators kernel system unicode io.files
4 io.files.info io.files.info.unix generalizations
5 strings arrays sequences math.parser unix.groups unix.users
6 tools.files.private unix.stat math fry macros combinators.smart
7 io tools.files math.order prettyprint ;
12 : unix-execute>string ( str bools -- str' )
14 { { t t } [ >lower ] }
15 { { t f } [ >upper ] }
16 { { f t } [ drop "x" ] }
20 : permissions-string ( permissions -- str )
23 [ type>> file-type>ch 1string ]
24 [ user-read? read>string ]
25 [ user-write? write>string ]
26 [ [ uid? ] [ user-execute? ] bi 2array "s" unix-execute>string ]
27 [ group-read? read>string ]
28 [ group-write? write>string ]
29 [ [ gid? ] [ group-execute? ] bi 2array "s" unix-execute>string ]
30 [ other-read? read>string ]
31 [ other-write? write>string ]
32 [ [ sticky? ] [ other-execute? ] bi 2array "t" unix-execute>string ]
34 ] output>array concat ;
36 : mode>symbol ( mode -- ch )
39 { [ dup S_IFDIR = ] [ drop "/" ] }
40 { [ dup S_IFIFO = ] [ drop "|" ] }
41 { [ dup any-execute? ] [ drop "*" ] }
42 { [ dup S_IFLNK = ] [ drop "@" ] }
43 { [ dup S_IFWHT = ] [ drop "%" ] }
44 { [ dup S_IFSOCK = ] [ drop "=" ] }
51 +permissions+ +nlinks+ +user+ +group+
52 +file-size+ +file-date+ +file-name+
54 { { directory-entry>> name>> <=> } } >>sort
55 [ [ list-files ] with-group-cache ] with-user-cache ;
57 M: unix file-spec>string
60 directory-entry>> [ name>> ] [ file-type>trailing ] bi append
62 { +permissions+ [ file-info>> permissions-string ] }
63 { +nlinks+ [ file-info>> nlink>> number>string ] }
64 { +user+ [ file-info>> uid>> user-name ] }
65 { +group+ [ file-info>> gid>> group-name ] }
66 { +uid+ [ file-info>> uid>> number>string ] }
67 { +gid+ [ file-info>> gid>> number>string ] }