io.files.info: use directory?, symbolic-link?, and regular-file?.

db4
John Benediktsson 2015-08-05 18:33:35 -07:00
parent 136d793c6e
commit 2a3427bdff
8 changed files with 13 additions and 15 deletions

View File

@ -72,7 +72,7 @@ C: <ftp-disconnect> ftp-disconnect
: can-serve-file? ( path -- ? ) : can-serve-file? ( path -- ? )
{ {
[ exists? ] [ exists? ]
[ file-info type>> +regular-file+ = ] [ file-info regular-file? ]
[ serving? ] [ serving? ]
} 1&& ; } 1&& ;

View File

@ -10,7 +10,7 @@ IN: io.directories.hierarchy
: directory-tree-files% ( path prefix -- ) : directory-tree-files% ( path prefix -- )
[ dup directory-entries ] dip '[ [ dup directory-entries ] dip '[
[ name>> [ append-path ] [ _ prepend-path ] bi ] [ name>> [ append-path ] [ _ prepend-path ] bi ]
[ type>> +directory+ = ] bi over , [ directory? ] bi over ,
[ directory-tree-files% ] [ 2drop ] if [ directory-tree-files% ] [ 2drop ] if
] with each ; ] with each ;

View File

@ -27,7 +27,7 @@ ERROR: too-many-symlinks path n ;
: (follow-links) ( n path -- path' ) : (follow-links) ( n path -- path' )
over 0 = [ symlink-depth get too-many-symlinks ] when over 0 = [ symlink-depth get too-many-symlinks ] when
dup link-info type>> +symbolic-link+ = dup link-info symbolic-link?
[ [ 1 - ] [ follow-link ] bi* (follow-links) ] [ [ 1 - ] [ follow-link ] bi* (follow-links) ]
[ nip ] if ; inline recursive [ nip ] if ; inline recursive

View File

@ -2,11 +2,10 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs colors.constants combinators USING: accessors arrays assocs colors.constants combinators
combinators.short-circuit fry io.directories io.files combinators.short-circuit fry io.directories io.files
io.files.info io.pathnames kernel locals make math math.order io.files.info io.files.types io.pathnames kernel locals make
sequences sequences.private sorting splitting typed math math.order sequences sequences.private sorting splitting
unicode.categories unicode.data vectors vocabs vocabs.hierarchy unicode.categories unicode.data vectors vocabs vocabs.hierarchy
; ;
IN: tools.completion IN: tools.completion
<PRIVATE <PRIVATE
@ -115,11 +114,11 @@ PRIVATE>
: directory-paths ( directory -- alist ) : directory-paths ( directory -- alist )
dup '[ dup '[
[ [
[ dup _ prepend-path ] [ name>> dup _ prepend-path ]
[ file-info directory? [ path-separator append ] when ] [ directory? [ path-separator append ] when ]
bi swap bi swap
] { } map>assoc ] { } map>assoc
] with-directory-files ; ] with-directory-entries ;
PRIVATE> PRIVATE>

View File

@ -1,7 +1,7 @@
! Copyright (C) 2007, 2009 Slava Pestov. ! Copyright (C) 2007, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs combinators.short-circuit fry USING: accessors arrays assocs combinators.short-circuit fry
io.directories io.files io.files.types io.pathnames kernel make io.directories io.files io.files.info io.pathnames kernel make
memoize namespaces sequences sets sorting splitting vocabs memoize namespaces sequences sets sorting splitting vocabs
vocabs.loader vocabs.metadata ; vocabs.loader vocabs.metadata ;
IN: vocabs.hierarchy IN: vocabs.hierarchy
@ -17,7 +17,7 @@ M: vocab-prefix vocab-name name>> ;
: visible-dirs ( seq -- seq' ) : visible-dirs ( seq -- seq' )
[ [
{ {
[ type>> +directory+ = ] [ directory? ]
[ name>> "." head? not ] [ name>> "." head? not ]
} 1&& } 1&&
] filter ; ] filter ;

View File

@ -45,7 +45,7 @@ TUPLE: code-file
: include-file-name? ( name -- ? ) : include-file-name? ( name -- ? )
{ {
[ path-components [ "." head? ] any? not ] [ path-components [ "." head? ] any? not ]
[ link-info type>> +regular-file+ = ] [ link-info regular-file? ]
} 1&& ; } 1&& ;
: code-files ( dir -- files ) : code-files ( dir -- files )

View File

@ -27,7 +27,7 @@ IN: io.files.trash.unix
{ {
[ file-info directory? ] [ file-info directory? ]
[ sticky? ] [ sticky? ]
[ link-info type>> +symbolic-link+ = not ] [ link-info symbolic-link? not ]
} 1&& [ "invalid trash path" throw ] unless ; } 1&& [ "invalid trash path" throw ] unless ;
: trash-home ( -- path ) : trash-home ( -- path )

View File

@ -30,8 +30,7 @@ DEFER: write-tree
] 2bi #directories [ 1 + ] change-global ; ] 2bi #directories [ 1 + ] change-global ;
: write-entry ( entry indents -- ) : write-entry ( entry indents -- )
nl over type>> +directory+ = nl over directory? [ write-dir ] [ write-file ] if ;
[ write-dir ] [ write-file ] if ;
:: write-tree ( path indents -- ) :: write-tree ( path indents -- )
path [ path [