| 
									
										
										
										
											2008-11-14 01:25:00 -05:00
										 |  |  | ! Copyright (C) 2008 Doug Coleman. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-12-15 02:13:35 -05:00
										 |  |  | USING: accessors combinators kernel system unicode.case io.files | 
					
						
							| 
									
										
										
										
											2009-01-13 16:48:59 -05:00
										 |  |  | io.files.info io.files.info.unix generalizations | 
					
						
							| 
									
										
										
										
											2008-12-15 02:13:35 -05:00
										 |  |  | strings arrays sequences math.parser unix.groups unix.users | 
					
						
							| 
									
										
										
										
											2009-01-13 16:48:59 -05:00
										 |  |  | tools.files.private unix.stat math fry macros combinators.smart | 
					
						
							| 
									
										
										
										
											2009-05-15 00:23:06 -04:00
										 |  |  | io tools.files math.order prettyprint ;
 | 
					
						
							| 
									
										
										
										
											2008-12-02 22:49:59 -05:00
										 |  |  | IN: tools.files.unix | 
					
						
							| 
									
										
										
										
											2008-11-14 01:25:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-14 01:51:14 -05:00
										 |  |  | <PRIVATE
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-14 01:44:01 -05:00
										 |  |  | : unix-execute>string ( str bools -- str' )
 | 
					
						
							| 
									
										
										
										
											2008-11-14 01:25:00 -05:00
										 |  |  |     swap { | 
					
						
							|  |  |  |         { { t t } [ >lower ] } | 
					
						
							|  |  |  |         { { t f } [ >upper ] } | 
					
						
							|  |  |  |         { { f t } [ drop "x" ] } | 
					
						
							|  |  |  |         [ 2drop "-" ] | 
					
						
							|  |  |  |     } case ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-14 01:44:01 -05:00
										 |  |  | : permissions-string ( permissions -- str )
 | 
					
						
							| 
									
										
										
										
											2009-01-08 18:55:04 -05:00
										 |  |  |     [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             [ type>> file-type>ch 1string ] | 
					
						
							|  |  |  |             [ user-read? read>string ] | 
					
						
							|  |  |  |             [ user-write? write>string ] | 
					
						
							|  |  |  |             [ [ uid? ] [ user-execute? ] bi 2array "s" unix-execute>string ] | 
					
						
							|  |  |  |             [ group-read? read>string ] | 
					
						
							|  |  |  |             [ group-write? write>string ] | 
					
						
							|  |  |  |             [ [ gid? ] [ group-execute? ] bi 2array "s" unix-execute>string ] | 
					
						
							|  |  |  |             [ other-read? read>string ] | 
					
						
							|  |  |  |             [ other-write? write>string ] | 
					
						
							|  |  |  |             [ [ sticky? ] [ other-execute? ] bi 2array "t" unix-execute>string ] | 
					
						
							|  |  |  |         } cleave
 | 
					
						
							|  |  |  |     ] output>array concat ;
 | 
					
						
							| 
									
										
										
										
											2008-11-14 01:25:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-19 22:15:27 -05:00
										 |  |  | : mode>symbol ( mode -- ch )
 | 
					
						
							|  |  |  |     S_IFMT bitand
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         { [ dup S_IFDIR = ] [ drop "/" ] } | 
					
						
							|  |  |  |         { [ dup S_IFIFO = ] [ drop "|" ] } | 
					
						
							|  |  |  |         { [ dup any-execute? ] [ drop "*" ] } | 
					
						
							|  |  |  |         { [ dup S_IFLNK = ] [ drop "@" ] } | 
					
						
							|  |  |  |         { [ dup S_IFWHT = ] [ drop "%" ] } | 
					
						
							|  |  |  |         { [ dup S_IFSOCK = ] [ drop "=" ] } | 
					
						
							|  |  |  |         { [ t ] [ drop "" ] } | 
					
						
							|  |  |  |     } cond ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-14 01:44:01 -05:00
										 |  |  | M: unix (directory.) ( path -- lines )
 | 
					
						
							| 
									
										
										
										
											2009-01-13 16:48:59 -05:00
										 |  |  |     <listing-tool> | 
					
						
							| 
									
										
										
										
											2009-02-17 13:36:27 -05:00
										 |  |  |         { | 
					
						
							|  |  |  |             +permissions+ +nlinks+ +user+ +group+ | 
					
						
							|  |  |  |             +file-size+ +file-date+ +file-name+ | 
					
						
							|  |  |  |         } >>specs | 
					
						
							| 
									
										
										
										
											2009-01-13 16:48:59 -05:00
										 |  |  |         { { directory-entry>> name>> <=> } } >>sort | 
					
						
							|  |  |  |     [ [ list-files ] with-group-cache ] with-user-cache ;
 | 
					
						
							| 
									
										
										
										
											2008-11-14 01:51:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-13 16:48:59 -05:00
										 |  |  | M: unix file-spec>string ( file-listing spec -- string )
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-02-17 13:36:27 -05:00
										 |  |  |         { +file-name/type+ [ | 
					
						
							| 
									
										
										
										
											2009-01-13 16:48:59 -05:00
										 |  |  |             directory-entry>> [ name>> ] [ file-type>trailing ] bi append
 | 
					
						
							|  |  |  |         ] } | 
					
						
							| 
									
										
										
										
											2009-02-17 13:36:27 -05:00
										 |  |  |         { +permissions+ [ file-info>> permissions-string ] } | 
					
						
							|  |  |  |         { +nlinks+ [ file-info>> nlink>> number>string ] } | 
					
						
							|  |  |  |         { +user+ [ file-info>> uid>> user-name ] } | 
					
						
							|  |  |  |         { +group+ [ file-info>> gid>> group-name ] } | 
					
						
							|  |  |  |         { +uid+ [ file-info>> uid>> number>string ] } | 
					
						
							|  |  |  |         { +gid+ [ file-info>> gid>> number>string ] } | 
					
						
							| 
									
										
										
										
											2009-01-13 16:48:59 -05:00
										 |  |  |         [ call-next-method ] | 
					
						
							|  |  |  |     } case ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-13 19:44:47 -05:00
										 |  |  | PRIVATE>
 |