From dc52f177f529ca31277db3cd812a3a8708db3525 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 24 Mar 2010 17:52:28 -0500 Subject: [PATCH] Add utiltity words for io.files.unique --- basis/io/files/unique/unique-docs.factor | 20 +++++++++++++++----- basis/io/files/unique/unique.factor | 15 +++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/basis/io/files/unique/unique-docs.factor b/basis/io/files/unique/unique-docs.factor index a2051bd10a..7e8d166b32 100644 --- a/basis/io/files/unique/unique-docs.factor +++ b/basis/io/files/unique/unique-docs.factor @@ -54,12 +54,19 @@ HELP: with-unique-directory } { $description "Creates a directory with " { $link unique-directory } " and calls the quotation with the pathname on the stack using the " { $link with-temporary-directory } " combinator. The quotation can access the " { $link current-temporary-directory } " symbol for the name of the temporary directory. Subsequent unique files will be created in this unique directory until the combinator returns." } ; -HELP: move-file-unique +HELP: copy-file-unique { $values - { "path" "a pathname string" } { "directory" "a directory" } + { "path" "a pathname string" } { "prefix" string } { "suffix" string } { "path'" "a pathname string" } } -{ $description "Moves " { $snippet "path" } " to " { $snippet "directory" } " by creating a unique file in this directory. Returns the new path." } ; +{ $description "Copies " { $snippet "path" } " to a new unique file in the directory stored in " { $link current-temporary-directory } ". Returns the new path." } ; + +HELP: move-file-unique +{ $values + { "path" "a pathname string" } { "prefix" string } { "suffix" string } + { "path'" "a pathname string" } +} +{ $description "Moves " { $snippet "path" } " to a new unique file in the directory stored in " { $link current-temporary-directory } ". Returns the new path." } ; HELP: current-temporary-directory { $values @@ -98,7 +105,10 @@ ARTICLE: "io.files.unique" "Unique files" } "Default temporary directory:" { $subsections default-temporary-directory } -"Moving files into a directory safely:" -{ $subsections move-file-unique } ; +"Copying and moving files to a new unique file:" +{ $subsections + copy-file-unique + move-file-unique +} ; ABOUT: "io.files.unique" diff --git a/basis/io/files/unique/unique.factor b/basis/io/files/unique/unique.factor index 07f7b25140..5bf89b9520 100644 --- a/basis/io/files/unique/unique.factor +++ b/basis/io/files/unique/unique.factor @@ -70,10 +70,17 @@ PRIVATE> : unique-file ( prefix -- path ) "" make-unique-file ; -: move-file-unique ( path directory -- path' ) - [ - "" unique-file [ move-file ] keep - ] with-temporary-directory ; +: move-file-unique ( path prefix suffix -- path' ) + make-unique-file [ move-file ] keep ; + +: copy-file-unique ( path prefix suffix -- path' ) + make-unique-file [ copy-file ] keep ; + +: temporary-file ( -- path ) "" unique-file ; + +: with-working-directory ( path quot -- ) + over make-directories + dupd '[ _ _ with-temporary-directory ] with-directory ; inline { { [ os unix? ] [ "io.files.unique.unix" ] }