! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: combinators continuations fry io.backend io.directories io.directories.hierarchy io.pathnames kernel locals namespaces random.data sequences system vocabs ; IN: io.files.unique : touch-unique-file ( path -- ) normalize-path (touch-unique-file) ; SYMBOL: unique-length SYMBOL: unique-retries 10 unique-length set-global 10 unique-retries set-global : unique-file ( prefix suffix -- path ) '[ _ _ random-file-name glue dup touch-unique-file ] unique-retries get retry absolute-path ; :: cleanup-unique-file ( ..a prefix suffix quot: ( ..a path -- ..b ) -- ..b ) prefix suffix unique-file :> path [ path quot call ] [ path delete-file ] [ ] cleanup ; inline : unique-directory ( -- path ) [ random-file-name dup make-directory ] unique-retries get retry absolute-path ; :: with-unique-directory ( quot -- path ) unique-directory :> path path quot with-directory path ; inline :: cleanup-unique-directory ( quot -- ) unique-directory :> path [ path quot with-directory ] [ path delete-tree ] [ ] cleanup ; inline { { [ os unix? ] [ "io.files.unique.unix" ] } { [ os windows? ] [ "io.files.unique.windows" ] } } cond require