Eduardo Cavazos 2008-12-08 21:35:50 -06:00
commit 12f2bf3edb
12 changed files with 37 additions and 23 deletions

View File

@ -1,5 +0,0 @@
USING: io.backend ;
IN: io.files.unique.backend
HOOK: (make-unique-file) io-backend ( path -- )
HOOK: temporary-path io-backend ( -- path )

View File

@ -1,11 +1,13 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math math.bitwise math.parser
random sequences continuations namespaces
io.files io arrays io.files.unique.backend system
combinators vocabs.loader fry ;
USING: kernel math math.bitwise math.parser random sequences
continuations namespaces io.files io arrays system
combinators vocabs.loader fry io.backend ;
IN: io.files.unique
HOOK: touch-unique-file io-backend ( path -- )
HOOK: temporary-path io-backend ( -- path )
SYMBOL: unique-length
SYMBOL: unique-retries
@ -26,12 +28,17 @@ SYMBOL: unique-retries
PRIVATE>
: (make-unique-file) ( path prefix suffix -- path )
'[
_ _ _ unique-length get random-name glue append-path
dup touch-unique-file
] unique-retries get retry ;
: make-unique-file ( prefix suffix -- path )
temporary-path -rot
[
unique-length get random-name glue append-path
dup (make-unique-file)
] 3curry unique-retries get retry ;
[ temporary-path ] 2dip (make-unique-file) ;
: make-unique-file* ( prefix suffix -- path )
[ current-directory get ] 2dip (make-unique-file) ;
: with-unique-file ( prefix suffix quot: ( path -- ) -- )
[ make-unique-file ] dip [ delete-file ] bi ; inline

View File

@ -0,0 +1,11 @@
USING: io.paths kernel tools.test io.files.unique sequences
io.files namespaces sorting ;
IN: io.paths.tests
[ t ] [
[
10 [ "io.paths.test" "gogogo" make-unique-file* ] replicate
current-directory get t [ ] find-all-files
] with-unique-directory
[ natural-sort ] bi@ =
] unit-test

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays deques dlists io.files io.paths.private
USING: accessors arrays deques dlists io.files
kernel sequences system vocabs.loader fry continuations ;
IN: io.paths

View File

@ -1,13 +1,13 @@
! 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 ;
unix system io.files.unique ;
IN: io.unix.files.unique
: open-unique-flags ( -- flags )
{ O_RDWR O_CREAT O_EXCL } flags ;
M: unix (make-unique-file) ( path -- )
M: unix touch-unique-file ( path -- )
open-unique-flags file-mode open-file close-file ;
M: unix temporary-path ( -- path ) "/tmp" ;

View File

@ -1,9 +1,9 @@
USING: kernel system io.files.unique.backend
windows.kernel32 io.windows io.windows.files io.ports windows
destructors environment ;
USING: kernel system windows.kernel32 io.windows
io.windows.files io.ports windows destructors environment
io.files.unique ;
IN: io.windows.files.unique
M: windows (make-unique-file) ( path -- )
M: windows touch-unique-file ( path -- )
GENERIC_WRITE CREATE_NEW 0 open-file dispose ;
M: windows temporary-path ( -- path )

View File

@ -6,3 +6,6 @@ IN: tools.files.tests
\ directory. must-infer
[ ] [ "" directory. ] unit-test
[ ]
[ { device-name free-space used-space total-space percent-used } file-systems. ] unit-test

View File

@ -65,5 +65,3 @@ percent-used percent-free ;
{ [ os unix? ] [ "tools.files.unix" ] }
{ [ os windows? ] [ "tools.files.windows" ] }
} cond require
! { device-name free-space used-space total-space percent-used } file-systems.