complete file-info across *bsd, linux

db4
Doug Coleman 2008-10-06 17:17:14 -05:00
parent a0a17646c5
commit e0d6aadc8e
10 changed files with 123 additions and 21 deletions

View File

@ -4,7 +4,7 @@ USING: io.backend io.ports io.unix.backend io.files io
unix unix.stat unix.time kernel math continuations
math.bitwise byte-arrays alien combinators calendar
io.encodings.binary accessors sequences strings system
io.files.private destructors ;
io.files.private destructors vocabs.loader ;
IN: io.unix.files
@ -74,26 +74,14 @@ M: unix copy-file ( from to -- )
[ swap file-info permissions>> chmod io-error ]
2bi ;
: stat>type ( stat -- type )
stat-st_mode S_IFMT bitand {
{ S_IFREG [ +regular-file+ ] }
{ S_IFDIR [ +directory+ ] }
{ S_IFCHR [ +character-device+ ] }
{ S_IFBLK [ +block-device+ ] }
{ S_IFIFO [ +fifo+ ] }
{ S_IFLNK [ +symbolic-link+ ] }
{ S_IFSOCK [ +socket+ ] }
[ drop +unknown+ ]
} case ;
HOOK: stat>file-info os ( stat -- file-info )
: stat>file-info ( stat -- info )
{
[ stat>type ]
[ stat-st_size ]
[ stat-st_mode ]
[ stat-st_mtim timespec-sec seconds unix-1970 time+ ]
} cleave
\ file-info boa ;
HOOK: stat>type os ( stat -- file-info )
HOOK: new-file-info os ( -- class )
TUPLE: unix-file-info < file-info uid gid dev ino
nlink rdev blocks blocksize ;
M: unix file-info ( path -- info )
normalize-path file-status stat>file-info ;
@ -105,4 +93,45 @@ M: unix make-link ( path1 path2 -- )
normalize-path symlink io-error ;
M: unix read-link ( path -- path' )
normalize-path read-symbolic-link ;
normalize-path read-symbolic-link ;
M: unix new-file-info ( -- class ) unix-file-info new ;
M: unix stat>file-info ( stat -- file-info )
[ new-file-info ] dip
{
[ stat>type >>type ]
[ stat-st_size >>size ]
[ stat-st_mode >>permissions ]
[ stat-st_ctim timespec>unix-time >>created ]
[ stat-st_mtim timespec>unix-time >>modified ]
[ stat-st_atim timespec>unix-time >>accessed ]
[ stat-st_uid >>uid ]
[ stat-st_gid >>gid ]
[ stat-st_dev >>dev ]
[ stat-st_ino >>ino ]
[ stat-st_nlink >>nlink ]
[ stat-st_rdev >>rdev ]
[ stat-st_blocks >>blocks ]
[ stat-st_blksize >>blocksize ]
} cleave ;
M: unix stat>type ( stat -- type )
stat-st_mode S_IFMT bitand {
{ S_IFREG [ +regular-file+ ] }
{ S_IFDIR [ +directory+ ] }
{ S_IFCHR [ +character-device+ ] }
{ S_IFBLK [ +block-device+ ] }
{ S_IFIFO [ +fifo+ ] }
{ S_IFLNK [ +symbolic-link+ ] }
{ S_IFSOCK [ +socket+ ] }
[ drop +unknown+ ]
} case ;
! Linux has no extra fields in its stat struct
os {
{ macosx [ "io.unix.files.macosx" require ] }
{ freebsd [ "io.unix.files.freebsd" require ] }
{ netbsd [ "io.unix.files.netbsd" require ] }
{ openbsd [ "io.unix.files.openbsd" require ] }
} case

View File

@ -0,0 +1,17 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel alien.syntax math io.unix.files system
unix.stat accessors combinators calendar ;
IN: io.unix.files.freebsd
TUPLE: freebsd-file-info < unix-file-info birth-time flags gen ;
M: freebsd new-file-info ( -- class ) freebsd-file-info new ;
M: freebsd stat>file-info ( stat -- file-info )
[ call-next-method ] keep
{
[ stat-st_flags >>flags ]
[ stat-st_gen >>gen ]
[ stat-st_birthtimepsec timespec>timestamp >>birth-time ]
} cleave ;

View File

@ -0,0 +1 @@
unportable

View File

@ -0,0 +1,16 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel alien.syntax math io.unix.files system
unix.stat accessors combinators ;
IN: io.unix.files.macosx
TUPLE: macosx-file-info < unix-file-info flags gen ;
M: macosx new-file-info ( -- class ) macosx-file-info new ;
M: macosx stat>file-info ( stat -- file-info )
[ call-next-method ] keep
{
[ stat-st_flags >>flags ]
[ stat-st_gen >>gen ]
} cleave ;

View File

@ -0,0 +1 @@
unportable

View File

@ -0,0 +1,17 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel alien.syntax math io.unix.files system
unix.stat accessors combinators calendar ;
IN: io.unix.files.netbsd
TUPLE: netbsd-file-info < unix-file-info birth-time flags gen ;
M: netbsd new-file-info ( -- class ) netbsd-file-info new ;
M: netbsd stat>file-info ( stat -- file-info )
[ call-next-method ] keep
{
[ stat-st_flags >>flags ]
[ stat-st_gen >>gen ]
[ stat-st_birthtim timespec>timestamp >>birth-time ]
} cleave ;

View File

@ -0,0 +1 @@
unportable

View File

@ -0,0 +1,17 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel alien.syntax math io.unix.files system
unix.stat accessors combinators calendar ;
IN: io.unix.files.openbsd
TUPLE: openbsd-file-info < unix-file-info birth-time flags gen ;
M: openbsd new-file-info ( -- class ) openbsd-file-info new ;
M: openbsd stat>file-info ( stat -- file-info )
[ call-next-method ] keep
{
[ stat-st_flags >>flags ]
[ stat-st_gen >>gen ]
[ stat-st_birthtim timespec>timestamp >>birth-time ]
} cleave ;

View File

@ -0,0 +1 @@
unportable

View File

@ -1,3 +1,5 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel io.ports io.unix.backend math.bitwise
unix io.files.unique.backend system ;
IN: io.unix.files.unique