Add utiltity words for io.files.unique

release
Doug Coleman 2010-03-24 17:52:28 -05:00
parent b39e3f4700
commit dc52f177f5
2 changed files with 26 additions and 9 deletions

View File

@ -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"

View File

@ -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" ] }