! Copyright (C) 2004, 2009 Slava Pestov, Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.strings init io io.backend io.encodings
+USING: alien.strings io io.backend io.encodings
io.pathnames kernel kernel.private namespaces sequences
splitting system ;
IN: io.files
<PRIVATE
-PRIMITIVE: (exists?) ( path -- ? )
+PRIMITIVE: (file-exists?) ( path -- ? )
PRIVATE>
SYMBOL: +retry+ ! just try the operation again without blocking
: set-file-lines ( seq path encoding -- )
[ [ print ] each ] with-file-writer ;
-: change-file-lines ( path encoding quot -- )
+: change-file-lines ( ..a path encoding quot: ( ..a seq -- ..b seq' ) -- ..b )
[ [ file-lines ] dip call ]
[ drop set-file-lines ] 3bi ; inline
: set-file-contents ( seq path encoding -- )
[ write ] with-file-writer ;
-: change-file-contents ( path encoding quot -- )
+: change-file-contents ( ..a path encoding quot: ( ..a seq -- ..b seq' ) -- ..b )
[ [ file-contents ] dip call ]
[ drop set-file-contents ] 3bi ; inline
: with-file-appender ( path encoding quot -- )
[ <file-appender> ] dip with-output-stream ; inline
-: exists? ( path -- ? )
- normalize-path native-string>alien (exists?) ;
+: file-exists? ( path -- ? )
+ normalize-path native-string>alien (file-exists?) ;
! Current directory
<PRIVATE
HOOK: cwd io-backend ( -- path )
-M: object cwd ( -- path ) "." ;
+M: object cwd "." ;
PRIVATE>
] map-find drop
[ image-path parent-directory ] unless* "resource-path" set-global ;
-[
+STARTUP-HOOK: [
cwd current-directory set-global
OBJ-IMAGE special-object alien>native-string \ image-path set-global
OBJ-EXECUTABLE special-object alien>native-string \ vm-path set-global
init-resource-path
-] "io.files" add-startup-hook
+]