factor/basis/io/files/unique/unique-docs.factor

60 lines
3.4 KiB
Factor
Raw Normal View History

USING: help.markup help.syntax io.directories io.pathnames
quotations strings ;
IN: io.files.unique
2008-12-08 22:53:42 -05:00
HELP: touch-unique-file
{ $values { "path" "a pathname string" } }
2008-12-08 22:53:42 -05:00
{ $description "Creates a unique file in a platform-specific way. The file is guaranteed not to exist and is openable by your user." } ;
HELP: unique-length
{ $description "A symbol storing the number of random characters inserted between the prefix and suffix of a random file name." } ;
HELP: unique-retries
{ $description "The number of times to try creating a unique file in case of a name collision. The odds of a name collision are extremely low with a sufficient " { $link unique-length } "." } ;
{ unique-length unique-retries } related-words
HELP: unique-file
{ $values { "prefix" string } { "suffix" string } { "path" "a pathname string" } }
{ $description "Creates a file that is guaranteed not to exist in the " { $link current-directory } ". The file name is composed of a prefix, a " { $link unique-length } " number of random digits and letters, and the suffix. Returns the full pathname." }
{ $errors "Throws an error if a new unique file cannot be created after a " { $link unique-retries } " number of tries. The most likely error is incorrect directory permissions on the " { $link current-directory } "." } ;
2008-12-08 22:53:42 -05:00
{ unique-file cleanup-unique-file } related-words
2008-12-08 22:53:42 -05:00
2009-03-23 02:18:24 -04:00
HELP: cleanup-unique-file
{ $values { "prefix" string } { "suffix" string } { "quot" { $quotation ( ..a path -- ..b ) } } }
{ $description "Creates a file with " { $link unique-file } " and calls the quotation with the path name on the stack." }
{ $notes "The unique file will be deleted after calling this word, even if an error is thrown in the quotation." } ;
2009-03-23 02:18:24 -04:00
HELP: unique-directory
{ $values { "path" "a pathname string" } }
{ $description "Creates a directory in the " { $link current-directory } " that is guaranteed not to exist and return the full pathname. The mechanism for the guarantee of uniqueness is retrying with a " { $link unique-length } " randomly generated filename until " { $link make-directory } " succeeds." }
{ $errors "Throws an error if the directory cannot be created after a " { $link unique-retries } " number of tries. The most likely error is incorrect directory permissions on the " { $link current-directory } "." } ;
HELP: with-unique-directory
{ $values { "quot" quotation } { "path" "a pathname string" } }
{ $description "Creates a directory with " { $link unique-directory } " and calls the quotation using " { $link with-directory } " to set it as the " { $link current-directory } "." } ;
2010-03-24 18:52:28 -04:00
HELP: cleanup-unique-directory
{ $values { "quot" quotation } }
{ $description "Creates a directory with " { $link unique-directory } " and calls the quotation using " { $link with-directory } " to set it as the " { $link current-directory } "." }
{ $notes "The unique directory will be deleted after calling this word, even if an error is thrown in the quotation." } ;
{ unique-directory with-unique-directory cleanup-unique-directory } related-words
ARTICLE: "io.files.unique" "Unique files"
"The " { $vocab-link "io.files.unique" } " vocabulary implements cross-platform unique file creation in a high-level and secure way." $nl
"Creating unique files:"
{ $subsections
unique-file
cleanup-unique-file
}
"Creating unique directories:"
{ $subsections
unique-directory
with-unique-directory
cleanup-unique-directory
2010-03-24 18:52:28 -04:00
} ;
ABOUT: "io.files.unique"