2008-12-14 21:03:00 -05:00
|
|
|
! Copyright (C) 2008 Doug Coleman, Eduardo Cavazos.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: accessors kernel system sequences combinators
|
2017-08-03 19:42:32 -04:00
|
|
|
vocabs vocabs.loader io.files io.files.types math ;
|
2008-12-14 21:03:00 -05:00
|
|
|
IN: io.files.info
|
|
|
|
|
|
|
|
! File info
|
2013-03-23 19:43:32 -04:00
|
|
|
TUPLE: file-info-tuple type size size-on-disk permissions created modified
|
2008-12-14 21:03:00 -05:00
|
|
|
accessed ;
|
|
|
|
|
|
|
|
HOOK: file-info os ( path -- info )
|
|
|
|
|
2017-08-03 19:42:32 -04:00
|
|
|
: ?file-info ( path -- info/f )
|
|
|
|
dup exists? [ file-info ] [ drop f ] if ; inline
|
|
|
|
|
2008-12-14 21:03:00 -05:00
|
|
|
HOOK: link-info os ( path -- info )
|
|
|
|
|
|
|
|
: directory? ( file-info -- ? ) type>> +directory+ = ;
|
2013-04-18 12:59:07 -04:00
|
|
|
: regular-file? ( file-info -- ? ) type>> +regular-file+ = ;
|
|
|
|
: symbolic-link? ( file-info -- ? ) type>> +symbolic-link+ = ;
|
2008-12-14 21:03:00 -05:00
|
|
|
|
2009-05-07 17:41:37 -04:00
|
|
|
: sparse-file? ( file-info -- ? )
|
|
|
|
[ size-on-disk>> ] [ size>> ] bi < ;
|
|
|
|
|
2008-12-14 21:03:00 -05:00
|
|
|
! File systems
|
|
|
|
HOOK: file-systems os ( -- array )
|
|
|
|
|
2013-03-23 19:43:32 -04:00
|
|
|
TUPLE: file-system-info-tuple device-name mount-point type
|
2008-12-14 21:03:00 -05:00
|
|
|
available-space free-space used-space total-space ;
|
|
|
|
|
|
|
|
HOOK: file-system-info os ( path -- file-system-info )
|
|
|
|
|
2012-10-24 19:44:12 -04:00
|
|
|
HOOK: file-readable? os ( path -- ? )
|
|
|
|
HOOK: file-writable? os ( path -- ? )
|
|
|
|
HOOK: file-executable? os ( path -- ? )
|
|
|
|
|
2020-01-03 11:48:24 -05:00
|
|
|
: mount-points ( -- assoc )
|
|
|
|
file-systems [ [ mount-point>> ] keep ] H{ } map>assoc ;
|
|
|
|
|
|
|
|
: (find-mount-point-info) ( path assoc -- mtab-entry )
|
|
|
|
[ resolve-symlinks ] dip
|
|
|
|
2dup at* [
|
|
|
|
2nip
|
|
|
|
] [
|
|
|
|
drop [ parent-directory ] dip (find-mount-point-info)
|
|
|
|
] if ;
|
|
|
|
|
|
|
|
: find-mount-point-info ( path -- file-system-info )
|
|
|
|
mount-points (find-mount-point-info) ;
|
|
|
|
|
2008-12-14 21:03:00 -05:00
|
|
|
{
|
2010-02-14 23:15:26 -05:00
|
|
|
{ [ os unix? ] [ "io.files.info.unix" ] }
|
2008-12-14 21:03:00 -05:00
|
|
|
{ [ os windows? ] [ "io.files.info.windows" ] }
|
2009-04-20 17:52:18 -04:00
|
|
|
} cond require
|