From db559f6f98522594be8ef9a9392fb6d95fab3abe Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sun, 24 Mar 2024 16:20:57 -0500 Subject: [PATCH] io.files.unique: add a word that opens a temp file and gives you a write stream --- basis/io/files/unique/unique.factor | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/basis/io/files/unique/unique.factor b/basis/io/files/unique/unique.factor index e5bdc599c8..0b3c59768a 100644 --- a/basis/io/files/unique/unique.factor +++ b/basis/io/files/unique/unique.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2008 Doug Coleman. ! See https://factorcode.org/license.txt for BSD license. USING: combinators continuations fry io.backend io.directories -io.pathnames kernel locals namespaces random.data sequences -system vocabs ; +io.files io.pathnames kernel locals namespaces random.data +sequences system vocabs ; IN: io.files.unique swap [ drop ] prepose attempt-all ; inline @@ -48,6 +51,9 @@ PRIVATE> ] recover ] unique-retries get retry [ absolute-path ] map ; +: with-unique-file-writer ( ..a prefix suffix encoding quot -- ..b path ) + [ random-file-name* ] 2dip [ with-file-writer-secure ] keepdd normalize-path ; inline + :: cleanup-unique-file ( ..a prefix suffix quot: ( ..a path -- ..b ) -- ..b ) prefix suffix unique-file :> path [ path quot call ] [ path delete-file ] finally ; inline -- 2.34.1