]> gitweb.factorcode.org Git - factor.git/commitdiff
io.files.unique: Add a way to create multiple unique files at the same time. If any...
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 23 May 2016 20:17:29 +0000 (13:17 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 23 May 2016 20:17:29 +0000 (13:17 -0700)
basis/io/files/unique/unique.factor

index 9ab84bb262631faa190dabe9ac617ee5524d1716..77d5628b15ffa0d1c16a5b5e8403cd74a7e4590f 100644 (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