fix file listing on windows, refactor tools.files cross-platform code

db4
U-FROGGER\erg 2009-01-13 18:44:47 -06:00
parent 406e5f6dac
commit cefd85013c
3 changed files with 12 additions and 17 deletions

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays calendar combinators fry io io.directories
io.files.info kernel math math.parser prettyprint sequences system
vocabs.loader sorting.slots ;
vocabs.loader sorting.slots calendar.format ;
IN: tools.files
<PRIVATE
@ -18,7 +18,7 @@ IN: tools.files
[ hour>> ] [ minute>> ] bi
[ number>string 2 CHAR: 0 pad-left ] bi@ ":" glue ;
: listing-timestamp ( timestamp -- string )
: listing-date ( timestamp -- string )
[ month>> month-abbreviation ]
[ day>> number>string 2 CHAR: \s pad-left ]
[
@ -36,7 +36,7 @@ IN: tools.files
PRIVATE>
SYMBOLS: file-name file-name/type permissions file-type nlinks file-size
file-datetime file-time uid gid user group link-target unix-datetime
file-date file-time file-datetime uid gid user group link-target unix-datetime
directory-or-size ;
TUPLE: listing-tool path specs sort ;
@ -61,6 +61,10 @@ M: object file-spec>string ( file-listing spec -- string )
{
{ file-name [ directory-entry>> name>> ] }
{ directory-or-size [ file-info>> dir-or-size ] }
{ file-size [ file-info>> size>> number>string ] }
{ file-date [ file-info>> modified>> listing-date ] }
{ file-time [ file-info>> modified>> listing-time ] }
{ file-datetime [ file-info>> modified>> timestamp>ymdhms ] }
[ unknown-file-spec ]
} case ;
@ -119,4 +123,4 @@ percent-used percent-free ;
{
{ [ os unix? ] [ "tools.files.unix" ] }
{ [ os windows? ] [ "tools.files.windows" ] }
} cond require
} cond require

View File

@ -47,7 +47,7 @@ IN: tools.files.unix
M: unix (directory.) ( path -- lines )
<listing-tool>
{ permissions nlinks user group file-size file-datetime file-name } >>specs
{ permissions nlinks user group file-size file-date file-name } >>specs
{ { directory-entry>> name>> <=> } } >>sort
[ [ list-files ] with-group-cache ] with-user-cache ;
@ -58,14 +58,11 @@ M: unix file-spec>string ( file-listing spec -- string )
] }
{ permissions [ file-info>> permissions-string ] }
{ nlinks [ file-info>> nlink>> number>string ] }
{ file-size [ file-info>> size>> 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 ] }
{ file-datetime [ file-info>> modified>> listing-timestamp ] }
{ file-time [ file-info>> modified>> listing-time ] }
[ call-next-method ]
} case ;
PRIVATE>
PRIVATE>

View File

@ -2,20 +2,14 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors calendar.format combinators io.files
kernel math.parser sequences splitting system tools.files
generalizations tools.files.private io.files.info ;
generalizations tools.files.private io.files.info math.order ;
IN: tools.files.windows
<PRIVATE
M: windows file-spec>string ( file-listing spec -- string )
{
{ listing-datetime [ modified>> timestamp>ymdhms ] }
[ call-next-method ]
} case ;
M: windows (directory.) ( entries -- lines )
<listing-tool>
{ file-size file-datetime file-name } >>specs
{ file-datetime directory-or-size file-name } >>specs
{ { directory-entry>> name>> <=> } } >>sort
list-files ;