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