From b8ac5780512b2a95d2a13222e83fcac45eca812c Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 11 Jun 2010 16:54:30 -0500 Subject: [PATCH] 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 --- basis/io/files/unique/unique.factor | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/basis/io/files/unique/unique.factor b/basis/io/files/unique/unique.factor index 5bf89b9520..7652bfcfd0 100644 --- a/basis/io/files/unique/unique.factor +++ b/basis/io/files/unique/unique.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays combinators continuations fry io io.backend 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 ; IN: io.files.unique @@ -78,9 +78,10 @@ PRIVATE> : temporary-file ( -- path ) "" unique-file ; -: with-working-directory ( path quot -- ) - over make-directories - dupd '[ _ _ with-temporary-directory ] with-directory ; inline +:: cleanup-unique-working-directory ( quot -- ) + unique-directory :> path + path [ path quot with-temporary-directory ] with-directory + path delete-tree ; inline { { [ os unix? ] [ "io.files.unique.unix" ] }