Add a combinator to make a unique directory, set that to the current and temp directories, and then delete the directory when done. Useful when working with apps that need to write intermediate files to the current directory
parent
f330e069c1
commit
b8ac578051
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays combinators continuations fry io io.backend
|
USING: arrays combinators continuations fry io io.backend
|
||||||
io.directories io.directories.hierarchy io.files io.pathnames
|
io.directories io.directories.hierarchy io.files io.pathnames
|
||||||
kernel math math.bitwise math.parser namespaces random
|
kernel locals math math.bitwise math.parser namespaces random
|
||||||
sequences system vocabs.loader ;
|
sequences system vocabs.loader ;
|
||||||
IN: io.files.unique
|
IN: io.files.unique
|
||||||
|
|
||||||
|
|
@ -78,9 +78,10 @@ PRIVATE>
|
||||||
|
|
||||||
: temporary-file ( -- path ) "" unique-file ;
|
: temporary-file ( -- path ) "" unique-file ;
|
||||||
|
|
||||||
: with-working-directory ( path quot -- )
|
:: cleanup-unique-working-directory ( quot -- )
|
||||||
over make-directories
|
unique-directory :> path
|
||||||
dupd '[ _ _ with-temporary-directory ] with-directory ; inline
|
path [ path quot with-temporary-directory ] with-directory
|
||||||
|
path delete-tree ; inline
|
||||||
|
|
||||||
{
|
{
|
||||||
{ [ os unix? ] [ "io.files.unique.unix" ] }
|
{ [ os unix? ] [ "io.files.unique.unix" ] }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue