io.files.unique: Add a way to create multiple unique files at the same time. If any of them fail, then the whole operation fails.

locals-and-roots
Doug Coleman 2016-05-23 13:17:29 -07:00
parent 0e55a173a0
commit 48d9b2b4eb
1 changed files with 12 additions and 0 deletions

View File

@ -36,10 +36,22 @@ PRIVATE>
dup touch-unique-file
] unique-retries get retry absolute-path ;
: unique-files ( prefix suffixes -- paths )
'[
_ _ [
random-file-name glue
dup touch-unique-file
] with map
] unique-retries get retry [ absolute-path ] map ;
:: cleanup-unique-file ( ..a prefix suffix quot: ( ..a path -- ..b ) -- ..b )
prefix suffix unique-file :> path
[ path quot call ] [ path delete-file ] [ ] cleanup ; inline
:: cleanup-unique-files ( ..a prefix suffixes quot: ( ..a path -- ..b ) -- ..b )
prefix suffixes unique-files :> paths
[ paths quot call ] [ paths [ delete-file ] each ] [ ] cleanup ; inline
: unique-directory ( -- path )
[
random-file-name