io.files split up and general refactoring work in progress

Slava Pestov 2008-12-14 20:03:00 -06:00
parent 59f7b60f4d
commit 50e214c152
200 changed files with 1441 additions and 1535 deletions

View File

@ -1,12 +1,11 @@
USING: system vocabs vocabs.loader kernel combinators
namespaces sequences io.backend ;
namespaces sequences io.backend accessors ;
IN: bootstrap.io
"bootstrap.compiler" vocab [
"io." {
"io.backend." {
{ [ "io-backend" get ] [ "io-backend" get ] }
{ [ os unix? ] [ "unix" ] }
{ [ os unix? ] [ "unix." os name>> append ] }
{ [ os winnt? ] [ "windows.nt" ] }
{ [ os wince? ] [ "windows.ce" ] }
} cond append require
] when

View File

@ -1,11 +1,11 @@
! Copyright (C) 2004, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors init namespaces words io
kernel.private math memory continuations kernel io.files
io.backend system parser vocabs sequences
vocabs.loader combinators splitting source-files strings
definitions assocs compiler.errors compiler.units
math.parser generic sets command-line ;
USING: accessors init namespaces words io kernel.private math
memory continuations kernel io.files io.pathnames io.backend
system parser vocabs sequences vocabs.loader combinators
splitting source-files strings definitions assocs
compiler.errors compiler.units math.parser generic sets
command-line ;
IN: bootstrap.stage2
SYMBOL: core-bootstrap-time

View File

@ -1,8 +1,8 @@
! Copyright (C) 2003, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: init continuations hashtables io io.encodings.utf8
io.files kernel kernel.private namespaces parser sequences
strings system splitting vocabs.loader ;
io.files io.pathnames kernel kernel.private namespaces parser
sequences strings system splitting vocabs.loader ;
IN: command-line
SYMBOL: script

View File

@ -2,10 +2,10 @@
! See http://factorcode.org/license.txt for BSD license.
USING: slots arrays definitions generic hashtables summary io
kernel math namespaces make prettyprint prettyprint.config
sequences assocs sequences.private strings io.styles io.files
vectors words system splitting math.parser classes.mixin
classes.tuple continuations continuations.private combinators
generic.math classes.builtin classes compiler.units
sequences assocs sequences.private strings io.styles
io.pathnames vectors words system splitting math.parser
classes.mixin classes.tuple continuations continuations.private
combinators generic.math classes.builtin classes compiler.units
generic.standard vocabs init kernel.private io.encodings
accessors math.order destructors source-files parser
classes.tuple.parser effects.parser lexer compiler.errors

View File

@ -1,5 +1,4 @@
USING: io.unix.backend kernel namespaces editors.gvim
system ;
USING: kernel namespaces editors.gvim system ;
IN: editors.gvim.unix
M: unix gvim-path

View File

@ -1,5 +1,5 @@
USING: editors.gvim io.files io.windows kernel namespaces
sequences windows.shell32 io.paths.windows system ;
USING: editors.gvim io.files kernel namespaces sequences
windows.shell32 io.paths.windows system ;
IN: editors.gvim.windows
M: windows gvim-path

View File

@ -3,7 +3,7 @@
USING: combinators.short-circuit accessors combinators io
io.encodings.8-bit io.encodings io.encodings.binary
io.encodings.utf8 io.files io.sockets kernel math.parser
namespaces make sequences ftp io.unix.launcher.parser
namespaces make sequences ftp io.launcher.unix.parser
unicode.case splitting assocs classes io.servers.connection
destructors calendar io.timeouts io.streams.duplex threads
continuations math concurrency.promises byte-arrays

View File

@ -1,9 +1,9 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: namespaces system kernel accessors assocs continuations
unix io.backend io.unix.backend io.unix.multiplexers
io.unix.multiplexers.kqueue ;
IN: io.unix.bsd
unix io.backend io.backend.unix io.backend.unix.multiplexers
io.backend.unix.multiplexers.kqueue io.files.unix ;
IN: io.backend.unix.bsd
M: bsd init-io ( -- )
<kqueue-mx> mx set-global ;

View File

@ -0,0 +1,3 @@
USING: io.backend.unix.bsd io.backend system ;
freebsd set-io-backend

View File

@ -1,8 +1,9 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel system namespaces io.backend io.unix.backend
io.unix.multiplexers io.unix.multiplexers.epoll ;
IN: io.unix.linux
USING: kernel system namespaces io.files.unix io.backend
io.backend.unix io.backend.unix.multiplexers
io.backend.unix.multiplexers.epoll ;
IN: io.backend.unix.linux
M: linux init-io ( -- )
<epoll-mx> mx set-global ;

View File

@ -1,8 +1,8 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: io.backend system namespaces io.unix.multiplexers
io.unix.multiplexers.run-loop ;
IN: io.unix.macosx
USING: io.backend system namespaces io.backend.unix.bsd
io.backend.unix.multiplexers io.backend.unix.multiplexers.run-loop ;
IN: io.backend.macosx
M: macosx init-io ( -- )
<run-loop-mx> mx set-global ;

View File

@ -2,9 +2,9 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types kernel destructors bit-arrays
sequences assocs struct-arrays math namespaces locals fry unix
unix.linux.epoll unix.time io.ports io.unix.backend
io.unix.multiplexers ;
IN: io.unix.multiplexers.epoll
unix.linux.epoll unix.time io.ports io.backend.unix
io.backend.unix.multiplexers ;
IN: io.backend.unix.multiplexers.epoll
TUPLE: epoll-mx < mx events ;

View File

@ -1,9 +1,9 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types combinators destructors
io.unix.backend kernel math.bitwise sequences struct-arrays unix
unix.kqueue unix.time assocs io.unix.multiplexers ;
IN: io.unix.multiplexers.kqueue
io.backend.unix kernel math.bitwise sequences struct-arrays unix
unix.kqueue unix.time assocs io.backend.unix.multiplexers ;
IN: io.backend.unix.multiplexers.kqueue
TUPLE: kqueue-mx < mx events ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors assocs sequences threads ;
IN: io.unix.multiplexers
IN: io.backend.unix.multiplexers
TUPLE: mx fd reads writes ;

View File

@ -1,10 +1,10 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel arrays namespaces math accessors alien locals
destructors system threads io.unix.multiplexers
io.unix.multiplexers.kqueue core-foundation
destructors system threads io.backend.unix.multiplexers
io.backend.unix.multiplexers.kqueue core-foundation
core-foundation.run-loop ;
IN: io.unix.multiplexers.run-loop
IN: io.backend.unix.multiplexers.run-loop
TUPLE: run-loop-mx kqueue-mx ;

View File

@ -2,8 +2,8 @@
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types kernel bit-arrays sequences assocs unix
math namespaces accessors math.order locals unix.time fry
io.ports io.unix.backend io.unix.multiplexers ;
IN: io.unix.multiplexers.select
io.ports io.backend.unix io.backend.unix.multiplexers ;
IN: io.backend.unix.multiplexers.select
TUPLE: select-mx < mx read-fdset write-fdset ;

View File

@ -0,0 +1,3 @@
USING: io.backend.unix.bsd io.backend system ;
netbsd set-io-backend

View File

@ -0,0 +1,3 @@
USING: io.backend.unix.bsd io.backend system ;
openbsd set-io-backend

View File

@ -2,7 +2,7 @@ USING: io.files io.sockets io kernel threads
namespaces tools.test continuations strings byte-arrays
sequences prettyprint system io.encodings.binary io.encodings.ascii
io.streams.duplex destructors make ;
IN: io.unix.tests
IN: io.backend.unix.tests
! Unix domain stream sockets
: socket-server "unix-domain-socket-test" temp-file ;

View File

@ -5,9 +5,9 @@ kernel.private math io.ports sequences strings sbufs threads
unix vectors io.buffers io.backend io.encodings math.parser
continuations system libc qualified namespaces make io.timeouts
io.encodings.utf8 destructors accessors summary combinators
locals unix.time fry io.unix.multiplexers ;
locals unix.time fry io.backend.unix.multiplexers ;
QUALIFIED: io
IN: io.unix.backend
IN: io.backend.unix
GENERIC: handle-fd ( handle -- fd )

View File

@ -1,11 +1,11 @@
USING: alien alien.c-types arrays assocs combinators
continuations destructors io io.backend io.ports io.timeouts
io.windows io.windows.files io.files io.buffers io.streams.c
io.backend.windows io.files.windows io.files io.buffers io.streams.c
libc kernel math namespaces sequences threads windows
windows.errors windows.kernel32 strings splitting qualified
ascii system accessors locals ;
QUALIFIED: windows.winsock
IN: io.windows.nt.backend
IN: io.backend.windows.nt
! Global variable with assoc mapping overlapped to threads
SYMBOL: pending-overlapped

View File

@ -1,9 +1,9 @@
USING: alien alien.c-types alien.syntax arrays continuations
destructors generic io.mmap io.ports io.windows io.windows.files
destructors generic io.mmap io.ports io.backend.windows io.files.windows
kernel libc math math.bitwise namespaces quotations sequences windows
windows.advapi32 windows.kernel32 io.backend system accessors
io.windows.privileges ;
IN: io.windows.nt.privileges
io.backend.windows.privileges ;
IN: io.backend.windows.nt.privileges
TYPEDEF: TOKEN_PRIVILEGES* PTOKEN_PRIVILEGES

View File

@ -1,6 +1,6 @@
USING: io.backend kernel continuations sequences
system vocabs.loader combinators ;
IN: io.windows.privileges
IN: io.backend.windows.privileges
HOOK: set-privilege io-backend ( name ? -- ) inline
@ -9,6 +9,6 @@ HOOK: set-privilege io-backend ( name ? -- ) inline
swap [ [ f set-privilege ] each ] curry [ ] cleanup ; inline
{
{ [ os winnt? ] [ "io.windows.nt.privileges" require ] }
{ [ os wince? ] [ "io.windows.ce.privileges" require ] }
{ [ os winnt? ] [ "io.backend.windows.nt.privileges" require ] }
{ [ os wince? ] [ "io.backend.windows.ce.privileges" require ] }
} cond

View File

View File

@ -5,7 +5,7 @@ io.buffers io.files io.ports io.binary io.timeouts
windows.errors strings kernel math namespaces sequences windows
windows.kernel32 windows.shell32 windows.types windows.winsock
splitting continuations math.bitwise system accessors ;
IN: io.windows
IN: io.backend.windows
: set-inherit ( handle ? -- )
[ HANDLE_FLAG_INHERIT ] dip

View File

@ -0,0 +1,191 @@
IN: io.directories
HELP: cwd
{ $values { "path" "a pathname string" } }
{ $description "Outputs the current working directory of the Factor process." }
{ $errors "Windows CE has no concept of ``current directory'', so this word throws an error there." }
{ $notes "User code should use " { $link with-directory } " or " { $link set-current-directory } " instead." } ;
HELP: cd
{ $values { "path" "a pathname string" } }
{ $description "Changes the current working directory of the Factor process." }
{ $errors "Windows CE has no concept of ``current directory'', so this word throws an error there." }
{ $notes "User code should use " { $link with-directory } " or " { $link set-current-directory } " instead." } ;
{ cd cwd current-directory set-current-directory with-directory } related-words
HELP: current-directory
{ $description "A variable holding the current directory as an absolute path. Words that use the filesystem do so in relation to this variable."
$nl
"This variable should never be set directly; instead, use " { $link set-current-directory } " or " { $link with-directory } ". This preserves the invariant that the value of this variable is an absolute path." } ;
HELP: set-current-directory
{ $values { "path" "a pathname string" } }
{ $description "Changes the " { $link current-directory } " variable."
$nl
"If " { $snippet "path" } " is relative, it is first resolved relative to the current directory. If " { $snippet "path" } " is absolute, it becomes the new current directory." } ;
HELP: with-directory
{ $values { "path" "a pathname string" } { "quot" quotation } }
{ $description "Calls the quotation in a new dynamic scope with the " { $link current-directory } " variable rebound."
$nl
"If " { $snippet "path" } " is relative, it is first resolved relative to the current directory. If " { $snippet "path" } " is absolute, it becomes the new current directory." } ;
HELP: (directory-entries)
{ $values { "path" "a pathname string" } { "seq" "a sequence of " { $snippet "{ name dir? }" } " pairs" } }
{ $description "Outputs the contents of a directory named by " { $snippet "path" } "." }
{ $notes "This is a low-level word, and user code should call one of the related words instead." } ;
HELP: directory-entries
{ $values { "path" "a pathname string" } { "seq" "a sequence of " { $link directory-entry } " objects" } }
{ $description "Outputs the contents of a directory named by " { $snippet "path" } "." } ;
HELP: directory-files
{ $values { "path" "a pathname string" } { "seq" "a sequence of filenames" } }
{ $description "Outputs the contents of a directory named by " { $snippet "path" } "." } ;
HELP: with-directory-files
{ $values { "path" "a pathname string" } { "quot" quotation } }
{ $description "Calls the quotation with the directory file names on the stack and with the directory set as the " { $link current-directory } ". Restores the current directory after the quotation is called." } ;
HELP: delete-file
{ $values { "path" "a pathname string" } }
{ $description "Deletes a file." }
{ $errors "Throws an error if the file could not be deleted." } ;
HELP: make-directory
{ $values { "path" "a pathname string" } }
{ $description "Creates a directory." }
{ $errors "Throws an error if the directory could not be created." } ;
HELP: make-directories
{ $values { "path" "a pathname string" } }
{ $description "Creates a directory and any parent directories which do not yet exist." }
{ $errors "Throws an error if the directories could not be created." } ;
HELP: delete-directory
{ $values { "path" "a pathname string" } }
{ $description "Deletes a directory. The directory must be empty." }
{ $errors "Throws an error if the directory could not be deleted." } ;
HELP: touch-file
{ $values { "path" "a pathname string" } }
{ $description "Updates the modification time of a file or directory. If the file does not exist, creates a new, empty file." }
{ $errors "Throws an error if the file could not be touched." } ;
HELP: delete-tree
{ $values { "path" "a pathname string" } }
{ $description "Deletes a file or directory, recursing into subdirectories." }
{ $errors "Throws an error if the deletion fails." }
{ $warning "Misuse of this word can lead to catastrophic data loss." } ;
HELP: move-file
{ $values { "from" "a pathname string" } { "to" "a pathname string" } }
{ $description "Moves or renames a file." }
{ $errors "Throws an error if the file does not exist or if the move operation fails." } ;
HELP: move-file-into
{ $values { "from" "a pathname string" } { "to" "a directory pathname string" } }
{ $description "Moves a file to another directory without renaming it." }
{ $errors "Throws an error if the file does not exist or if the move operation fails." } ;
HELP: move-files-into
{ $values { "files" "a sequence of pathname strings" } { "to" "a directory pathname string" } }
{ $description "Moves a set of files to another directory." }
{ $errors "Throws an error if the file does not exist or if the move operation fails." } ;
HELP: copy-file
{ $values { "from" "a pathname string" } { "to" "a pathname string" } }
{ $description "Copies a file." }
{ $notes "This operation attempts to preserve the original file's attributes, however not all attributes may be preserved." }
{ $errors "Throws an error if the file does not exist or if the copy operation fails." } ;
HELP: copy-file-into
{ $values { "from" "a pathname string" } { "to" "a directory pathname string" } }
{ $description "Copies a file to another directory." }
{ $errors "Throws an error if the file does not exist or if the copy operation fails." } ;
HELP: copy-files-into
{ $values { "files" "a sequence of pathname strings" } { "to" "a directory pathname string" } }
{ $description "Copies a set of files to another directory." }
{ $errors "Throws an error if the file does not exist or if the copy operation fails." } ;
HELP: copy-tree
{ $values { "from" "a pathname string" } { "to" "a pathname string" } }
{ $description "Copies a directory tree recursively." }
{ $notes "This operation attempts to preserve original file attributes, however not all attributes may be preserved." }
{ $errors "Throws an error if the copy operation fails." } ;
HELP: copy-tree-into
{ $values { "from" "a pathname string" } { "to" "a directory pathname string" } }
{ $description "Copies a directory tree to another directory, recursively." }
{ $errors "Throws an error if the copy operation fails." } ;
HELP: copy-trees-into
{ $values { "files" "a sequence of pathname strings" } { "to" "a directory pathname string" } }
{ $description "Copies a set of directory trees to another directory, recursively." }
{ $errors "Throws an error if the copy operation fails." } ;
ARTICLE: "current-directory" "Current working directory"
"File system I/O operations use the value of a variable to resolve relative pathnames:"
{ $subsection current-directory }
"This variable can be changed with a pair of words:"
{ $subsection set-current-directory }
{ $subsection with-directory }
"This variable is independent of the operating system notion of ``current working directory''. While all Factor I/O operations use the variable and not the operating system's value, care must be taken when making FFI calls which expect a pathname. The first option is to resolve relative paths:"
{ $subsection (normalize-path) }
"The second is to change the working directory of the current process:"
{ $subsection cd }
{ $subsection cwd } ;
ARTICLE: "io.directories.listing" "Directory listing"
"Directory listing:"
{ $subsection directory-entries }
{ $subsection directory-files }
{ $subsection with-directory-files } ;
ARTICLE: "io.directories.create" "Creating directories"
{ $subsection make-directory }
{ $subsection make-directories } ;
ARTICLE: "delete-move-copy" "Deleting, moving, and copying files"
"Operations for deleting and copying files come in two forms:"
{ $list
{ "Words named " { $snippet { $emphasis "operation" } "-file" } " which work on regular files only." }
{ "Words named " { $snippet { $emphasis "operation" } "-tree" } " works on directory trees recursively, and also accepts regular files." }
}
"The operations for moving and copying files come in three flavors:"
{ $list
{ "A word named " { $snippet { $emphasis "operation" } } " which takes a source and destination path." }
{ "A word named " { $snippet { $emphasis "operation" } "-into" } " which takes a source path and destination directory. The destination file will be stored in the destination directory and will have the same file name as the source path." }
{ "A word named " { $snippet { $emphasis "operation" } "s-into" } " which takes a sequence of source paths and destination directory." }
}
"Since both of the above lists apply to copying files, that this means that there are a total of six variations on copying a file."
$nl
"Deleting files:"
{ $subsection delete-file }
{ $subsection delete-directory }
{ $subsection delete-tree }
"Moving files:"
{ $subsection move-file }
{ $subsection move-file-into }
{ $subsection move-files-into }
"Copying files:"
{ $subsection copy-file }
{ $subsection copy-file-into }
{ $subsection copy-files-into }
"Copying directory trees recursively:"
{ $subsection copy-tree }
{ $subsection copy-tree-into }
{ $subsection copy-trees-into }
"On most operating systems, files can only be moved within the same file system. To move files between file systems, use " { $link copy-file } " followed by " { $link delete-file } " on the old name." ;
ARTICLE: "io.directories" "Directory manipulation"
"The " { $vocab-link "io.directories" } " vocabulary defines words for inspecting and manipulating directory trees."
{ $subsection home }
{ $subsection "current-directory" }
{ $subsection "io.directories.listing" }
{ $subsection "io.directories.create" }
{ $subsection "delete-move-copy" } ;
ABOUT: "io.directories"

View File

@ -0,0 +1,199 @@
IN: io.directories.tests
[ { "kernel" } ] [
"core" resource-path [
"." directory-files [ "kernel" = ] filter
] with-directory
] unit-test
[ { "kernel" } ] [
"resource:core" [
"." directory-files [ "kernel" = ] filter
] with-directory
] unit-test
[ { "kernel" } ] [
"resource:core" [
[ "kernel" = ] filter
] with-directory-files
] unit-test
[ ] [ "blahblah" temp-file dup exists? [ delete-directory ] [ drop ] if ] unit-test
[ ] [ "blahblah" temp-file make-directory ] unit-test
[ t ] [ "blahblah" temp-file file-info directory? ] unit-test
[ t ] [
[ temp-directory "loldir" append-path delete-directory ] ignore-errors
temp-directory [
"loldir" make-directory
] with-directory
temp-directory "loldir" append-path exists?
] unit-test
[ ] [
[ temp-directory "loldir" append-path delete-directory ] ignore-errors
temp-directory [
"loldir" make-directory
"loldir" delete-directory
] with-directory
] unit-test
[ "file1 contents" ] [
[ temp-directory "loldir" append-path delete-directory ] ignore-errors
temp-directory [
"file1 contents" "file1" utf8 set-file-contents
"file1" "file2" copy-file
"file2" utf8 file-contents
] with-directory
"file1" temp-file delete-file
"file2" temp-file delete-file
] unit-test
[ "file3 contents" ] [
temp-directory [
"file3 contents" "file3" utf8 set-file-contents
"file3" "file4" move-file
"file4" utf8 file-contents
] with-directory
"file4" temp-file delete-file
] unit-test
[ "file5" temp-file delete-file ] ignore-errors
[ ] [
temp-directory [
"file5" touch-file
"file5" delete-file
] with-directory
] unit-test
[ "file6" temp-file delete-file ] ignore-errors
[ ] [
temp-directory [
"file6" touch-file
"file6" link-info drop
] with-directory
] unit-test
[ ] [
{ "Hello world." }
"test-foo.txt" temp-file ascii set-file-lines
] unit-test
[ ] [
"test-foo.txt" temp-file ascii [
"Hello appender." print
] with-file-appender
] unit-test
[ ] [
"test-bar.txt" temp-file ascii [
"Hello appender." print
] with-file-appender
] unit-test
[ "Hello world.\nHello appender.\n" ] [
"test-foo.txt" temp-file ascii file-contents
] unit-test
[ "Hello appender.\n" ] [
"test-bar.txt" temp-file ascii file-contents
] unit-test
[ ] [ "test-foo.txt" temp-file delete-file ] unit-test
[ ] [ "test-bar.txt" temp-file delete-file ] unit-test
[ f ] [ "test-foo.txt" temp-file exists? ] unit-test
[ f ] [ "test-bar.txt" temp-file exists? ] unit-test
[ "test-blah" temp-file delete-tree ] ignore-errors
[ ] [ "test-blah" temp-file make-directory ] unit-test
[ ] [
"test-blah/fooz" temp-file ascii <file-writer> dispose
] unit-test
[ t ] [
"test-blah/fooz" temp-file exists?
] unit-test
[ ] [ "test-blah/fooz" temp-file delete-file ] unit-test
[ ] [ "test-blah" temp-file delete-directory ] unit-test
[ f ] [ "test-blah" temp-file exists? ] unit-test
USE: debugger.threads
[ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test
[ ] [ "test-quux.txt" temp-file delete-file ] unit-test
[ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test
[ ] [ "test-quux.txt" "quux-test.txt" [ temp-file ] bi@ move-file ] unit-test
[ t ] [ "quux-test.txt" temp-file exists? ] unit-test
[ ] [ "quux-test.txt" temp-file delete-file ] unit-test
[ ] [ "delete-tree-test/a/b/c" temp-file make-directories ] unit-test
[ ] [
{ "Hi" }
"delete-tree-test/a/b/c/d" temp-file ascii set-file-lines
] unit-test
[ ] [
"delete-tree-test" temp-file delete-tree
] unit-test
[ ] [
"copy-tree-test/a/b/c" temp-file make-directories
] unit-test
[ ] [
"Foobar"
"copy-tree-test/a/b/c/d" temp-file
ascii set-file-contents
] unit-test
[ ] [
"copy-tree-test" temp-file
"copy-destination" temp-file copy-tree
] unit-test
[ "Foobar" ] [
"copy-destination/a/b/c/d" temp-file ascii file-contents
] unit-test
[ ] [
"copy-destination" temp-file delete-tree
] unit-test
[ ] [
"copy-tree-test" temp-file
"copy-destination" temp-file copy-tree-into
] unit-test
[ "Foobar" ] [
"copy-destination/copy-tree-test/a/b/c/d" temp-file ascii file-contents
] unit-test
[ ] [
"copy-destination/copy-tree-test/a/b/c/d" temp-file "" temp-file copy-file-into
] unit-test
[ "Foobar" ] [
"d" temp-file ascii file-contents
] unit-test
[ ] [ "d" temp-file delete-file ] unit-test
[ ] [ "copy-destination" temp-file delete-tree ] unit-test
[ ] [ "copy-tree-test" temp-file delete-tree ] unit-test

View File

@ -0,0 +1,112 @@
! Copyright (C) 2004, 2008 Slava Pestov, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: vocabs.loader combinators ;
IN: io.directories
: set-current-directory ( path -- )
(normalize-path) current-directory set ;
: with-directory ( path quot -- )
[ (normalize-path) current-directory ] dip with-variable ; inline
! Creating directories
HOOK: make-directory io-backend ( path -- )
: make-directories ( path -- )
normalize-path trim-right-separators {
{ [ dup "." = ] [ ] }
{ [ dup root-directory? ] [ ] }
{ [ dup empty? ] [ ] }
{ [ dup exists? ] [ ] }
[
dup parent-directory make-directories
dup make-directory
]
} cond drop ;
! Listing directories
TUPLE: directory-entry name type ;
HOOK: >directory-entry os ( byte-array -- directory-entry )
HOOK: (directory-entries) os ( path -- seq )
: directory-entries ( path -- seq )
normalize-path
(directory-entries)
[ name>> { "." ".." } member? not ] filter ;
: directory-files ( path -- seq )
directory-entries [ name>> ] map ;
: with-directory-files ( path quot -- )
[ "" directory-files ] prepose with-directory ; inline
! Touching files
HOOK: touch-file io-backend ( path -- )
! Deleting files
HOOK: delete-file io-backend ( path -- )
HOOK: delete-directory io-backend ( path -- )
: delete-tree ( path -- )
dup link-info type>> +directory+ = [
[ [ [ delete-tree ] each ] with-directory-files ]
[ delete-directory ]
bi
] [ delete-file ] if ;
: to-directory ( from to -- from to' )
over file-name append-path ;
! Moving and renaming files
HOOK: move-file io-backend ( from to -- )
: move-file-into ( from to -- )
to-directory move-file ;
: move-files-into ( files to -- )
[ move-file-into ] curry each ;
! Copying files
HOOK: copy-file io-backend ( from to -- )
M: object copy-file
dup parent-directory make-directories
binary <file-writer> [
swap binary <file-reader> [
swap stream-copy
] with-disposal
] with-disposal ;
: copy-file-into ( from to -- )
to-directory copy-file ;
: copy-files-into ( files to -- )
[ copy-file-into ] curry each ;
DEFER: copy-tree-into
: copy-tree ( from to -- )
normalize-path
over link-info type>>
{
{ +symbolic-link+ [ copy-link ] }
{ +directory+ [
swap [
[ swap copy-tree-into ] with each
] with-directory-files
] }
[ drop copy-file ]
} case ;
: copy-tree-into ( from to -- )
to-directory copy-tree ;
: copy-trees-into ( files to -- )
[ copy-tree-into ] curry each ;
{
{ [ os unix? ] [ "io.directories.unix" require ] }
} cond

View File

@ -0,0 +1,11 @@
USING: io.paths kernel tools.test io.files.unique sequences
io.files namespaces sorting ;
IN: io.paths.tests
[ t ] [
[
10 [ "io.paths.test" "gogogo" make-unique-file* ] replicate
current-directory get t [ ] find-all-files
] with-unique-directory
[ natural-sort ] bi@ =
] unit-test

View File

@ -0,0 +1,58 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays deques dlists io.files
kernel sequences system vocabs.loader fry continuations ;
IN: io.directories.search
TUPLE: directory-iterator path bfs queue ;
<PRIVATE
: qualified-directory ( path -- seq )
dup directory-files [ append-path ] with map ;
: push-directory ( path iter -- )
[ qualified-directory ] dip [
dup queue>> swap bfs>>
[ push-front ] [ push-back ] if
] curry each ;
: <directory-iterator> ( path bfs? -- iterator )
<dlist> directory-iterator boa
dup path>> over push-directory ;
: next-file ( iter -- file/f )
dup queue>> deque-empty? [ drop f ] [
dup queue>> pop-back dup link-info directory?
[ over push-directory next-file ] [ nip ] if
] if ;
: iterate-directory ( iter quot: ( obj -- ? ) -- obj )
over next-file [
over call
[ 2nip ] [ iterate-directory ] if*
] [
2drop f
] if* ; inline recursive
PRIVATE>
: find-file ( path bfs? quot: ( obj -- ? ) -- path/f )
[ <directory-iterator> ] dip
[ keep and ] curry iterate-directory ; inline
: each-file ( path bfs? quot: ( obj -- ? ) -- )
[ <directory-iterator> ] dip
[ f ] compose iterate-directory drop ; inline
: find-all-files ( path bfs? quot: ( obj -- ? ) -- paths )
[ <directory-iterator> ] dip
pusher [ [ f ] compose iterate-directory drop ] dip ; inline
: recursive-directory ( path bfs? -- paths )
[ ] accumulator [ each-file ] dip ;
: find-in-directories ( directories bfs? quot -- path' )
'[ _ _ find-file ] attempt-all ; inline
os windows? [ "io.paths.windows" require ] when

View File

@ -0,0 +1,13 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays continuations fry io.files io.paths
kernel windows.shell32 sequences ;
IN: io.paths.windows
: program-files-directories ( -- array )
program-files program-files-x86 2array ; inline
: find-in-program-files ( base-directory bfs? quot -- path )
[
[ program-files-directories ] dip '[ _ append-path ] map
] 2dip find-in-directories ; inline

View File

@ -0,0 +1,75 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: math.bitwise io.backend kernel io.files unix
io.backend.unix io.encodings.binary io.directories io destructors
accessors io.files.info alien.c-types io.encodings.utf8 fry
sequences system continuations alien.strings ;
IN: io.directories.unix
: touch-mode ( -- n )
{ O_WRONLY O_APPEND O_CREAT O_EXCL } flags ; foldable
M: unix touch-file ( path -- )
normalize-path
dup exists? [ touch ] [
touch-mode file-mode open-file close-file
] if ;
M: unix move-file ( from to -- )
[ normalize-path ] bi@ rename io-error ;
M: unix delete-file ( path -- ) normalize-path unlink-file ;
M: unix make-directory ( path -- )
normalize-path OCT: 777 mkdir io-error ;
M: unix delete-directory ( path -- )
normalize-path rmdir io-error ;
: (copy-file) ( from to -- )
dup parent-directory make-directories
binary <file-writer> [
swap binary <file-reader> [
swap stream-copy
] with-disposal
] with-disposal ;
M: unix copy-file ( from to -- )
[ normalize-path ] bi@
[ (copy-file) ]
[ swap file-info permissions>> chmod io-error ]
2bi ;
: with-unix-directory ( path quot -- )
[ opendir dup [ (io-error) ] unless ] dip
dupd curry swap '[ _ closedir io-error ] [ ] cleanup ; inline
: find-next-file ( DIR* -- byte-array )
"dirent" <c-object>
f <void*>
[ readdir_r 0 = [ (io-error) ] unless ] 2keep
*void* [ drop f ] unless ;
: dirent-type>file-type ( ch -- type )
{
{ DT_BLK [ +block-device+ ] }
{ DT_CHR [ +character-device+ ] }
{ DT_DIR [ +directory+ ] }
{ DT_LNK [ +symbolic-link+ ] }
{ DT_SOCK [ +socket+ ] }
{ DT_FIFO [ +fifo+ ] }
{ DT_REG [ +regular-file+ ] }
{ DT_WHT [ +whiteout+ ] }
[ drop +unknown+ ]
} case ;
M: unix >directory-entry ( byte-array -- directory-entry )
[ dirent-d_name utf8 alien>string ]
[ dirent-d_type dirent-type>file-type ] bi directory-entry boa ;
M: unix (directory-entries) ( path -- seq )
[
'[ _ find-next-file dup ]
[ >directory-entry ]
[ drop ] produce
] with-unix-directory ;

View File

@ -0,0 +1 @@
Daniel Ehrenberg

View File

@ -0,0 +1,11 @@
USING: help.syntax help.markup ;
IN: io.encodings.binary
HELP: binary
{ $class-description "Encoding descriptor for binary I/O." } ;
ARTICLE: "io.encodings.binary" "Binary encoding"
"Making an encoded stream with the binary encoding is a no-op; streams with this encoding deal with byte-arrays, not strings."
{ $subsection binary } ;
ABOUT: "io.encodings.binary"

View File

@ -0,0 +1,8 @@
! Copyright (C) 2008 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
USING: io.encodings kernel ;
IN: io.encodings.binary
SINGLETON: binary
M: binary <encoder> drop ;
M: binary <decoder> drop ;

View File

@ -0,0 +1 @@
Dummy encoding for binary I/O

View File

@ -0,0 +1 @@
text

View File

@ -0,0 +1,76 @@
IN: io.files.info
HELP: file-info
{ $values { "path" "a pathname string" } { "info" file-info } }
{ $description "Queries the file system for metadata. If " { $snippet "path" } " refers to a symbolic link, it is followed. See the article " { $link "file-types" } " for a list of metadata symbols." }
{ $errors "Throws an error if the file does not exist." } ;
HELP: link-info
{ $values { "path" "a pathname string" } { "info" "a file-info tuple" } }
{ $description "Queries the file system for metadata. If path refers to a symbolic link, information about the symbolic link itself is returned. If the file does not exist, an exception is thrown." } ;
{ file-info link-info } related-words
HELP: +regular-file+
{ $description "A regular file. This type exists on all platforms. See " { $link "file-streams" } " for words operating on files." } ;
HELP: +directory+
{ $description "A directory. This type exists on all platforms. See " { $link "directories" } " for words operating on directories." } ;
HELP: +symbolic-link+
{ $description "A symbolic link file. This type is currently implemented on Unix platforms only. See " { $link "symbolic-links" } " for words operating on symbolic links." } ;
HELP: +character-device+
{ $description "A Unix character device file. This type exists on Unix platforms only." } ;
HELP: +block-device+
{ $description "A Unix block device file. This type exists on Unix platforms only." } ;
HELP: +fifo+
{ $description "A Unix fifo file. This type exists on Unix platforms only." } ;
HELP: +socket+
{ $description "A Unix socket file. This type exists on Unix platforms only." } ;
HELP: +unknown+
{ $description "A unknown file type." } ;
HELP: directory?
{ $values { "file-info" file-info } { "?" "a boolean" } }
{ $description "Tests if " { $snippet "file-info" } " is a directory." } ;
HELP: file-systems
{ $values { "array" array } }
{ $description "Returns an array of " { $link file-system-info } " objects returned by iterating the mount points and calling " { $link file-system-info } " on each." } ;
HELP: file-system-info
{ $values
{ "path" "a pathname string" }
{ "file-system-info" file-system-info } }
{ $description "Returns a platform-specific object describing the file-system that contains the path. The cross-platform slot is " { $slot "free-space" } "." } ;
ARTICLE: "file-types" "File types"
"Platform-independent types:"
{ $subsection +regular-file+ }
{ $subsection +directory+ }
"Platform-specific types:"
{ $subsection +character-device+ }
{ $subsection +block-device+ }
{ $subsection +fifo+ }
{ $subsection +symbolic-link+ }
{ $subsection +socket+ }
{ $subsection +unknown+ } ;
ARTICLE: "io.files.info" "File system meta-data"
"File meta-data:"
{ $subsection file-info }
{ $subsection link-info }
{ $subsection exists? }
{ $subsection directory? }
"File types:"
{ $subsection "file-types" }
"File system meta-data:"
{ $subsection file-system-info }
{ $subsection file-systems } ;
ABOUT: "io.files.info"

View File

@ -0,0 +1,16 @@
IN: io.files.info.tests
\ file-info must-infer
\ link-info must-infer
[ t ] [
temp-directory [ "hi41" "test41" utf8 set-file-contents ] with-directory
temp-directory "test41" append-path utf8 file-contents "hi41" =
] unit-test
[ t ] [
temp-directory [ "test41" file-info size>> ] with-directory 4 =
] unit-test
[ t ] [ "/" file-system-info file-system-info? ] unit-test
[ t ] [ file-systems [ file-system-info? ] all? ] unit-test

View File

@ -0,0 +1,38 @@
! Copyright (C) 2008 Doug Coleman, Eduardo Cavazos.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel system sequences combinators
vocabs.loader ;
IN: io.files.info
! File info
TUPLE: file-info type size permissions created modified
accessed ;
HOOK: file-info os ( path -- info )
HOOK: link-info os ( path -- info )
SYMBOL: +regular-file+
SYMBOL: +directory+
SYMBOL: +symbolic-link+
SYMBOL: +character-device+
SYMBOL: +block-device+
SYMBOL: +fifo+
SYMBOL: +socket+
SYMBOL: +whiteout+
SYMBOL: +unknown+
: directory? ( file-info -- ? ) type>> +directory+ = ;
! File systems
HOOK: file-systems os ( -- array )
TUPLE: file-system-info device-name mount-point type
available-space free-space used-space total-space ;
HOOK: file-system-info os ( path -- file-system-info )
{
{ [ os unix? ] [ "io.files.info.unix." os name>> append ] }
{ [ os windows? ] [ "io.files.info.windows" ] }
} cond require

View File

@ -1,8 +1,9 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel alien.syntax math io.unix.files system
unix.stat accessors combinators calendar.unix ;
IN: io.unix.files.bsd
USING: kernel alien.syntax math io.files.unix system
unix.stat accessors combinators calendar.unix
io.files.info.unix ;
IN: io.files.info.unix.bsd
TUPLE: bsd-file-info < unix-file-info birth-time flags gen ;

View File

@ -1,11 +1,11 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.syntax combinators
io.backend io.files io.unix.files kernel math system unix
io.backend io.files io.files.unix kernel math system unix
unix.statfs.freebsd unix.statvfs.freebsd unix.getfsstat.freebsd
sequences grouping alien.strings io.encodings.utf8
specialized-arrays.direct.uint arrays ;
IN: io.unix.files.freebsd
specialized-arrays.direct.uint arrays io.files.info.unix ;
IN: io.files.info.unix.freebsd
TUPLE: freebsd-file-system-info < unix-file-system-info
version io-size owner syncreads syncwrites asyncreads asyncwrites ;

View File

@ -2,10 +2,10 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.syntax combinators csv
io.backend io.encodings.utf8 io.files io.streams.string
io.unix.files kernel math.order namespaces sequences sorting
io.files.unix kernel math.order namespaces sequences sorting
system unix unix.statfs.linux unix.statvfs.linux
specialized-arrays.direct.uint arrays ;
IN: io.unix.files.linux
specialized-arrays.direct.uint arrays io.files.info.unix ;
IN: io.files.info.unix.linux
TUPLE: linux-file-system-info < unix-file-system-info
namelen ;

View File

@ -2,9 +2,10 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.strings combinators
grouping io.encodings.utf8 io.files kernel math sequences
system unix io.unix.files specialized-arrays.direct.uint arrays
unix.statfs.macosx unix.statvfs.macosx unix.getfsstat.macosx ;
IN: io.unix.files.macosx
system unix io.files.unix specialized-arrays.direct.uint arrays
unix.statfs.macosx unix.statvfs.macosx unix.getfsstat.macosx
io.files.info.unix io.files.info ;
IN: io.files.info.unix.macosx
TUPLE: macosx-file-system-info < unix-file-system-info
io-size owner type-id filesystem-subtype ;

View File

@ -2,10 +2,11 @@
! See http://factorcode.org/license.txt for BSD license.
USING: alien.syntax kernel unix.stat math unix
combinators system io.backend accessors alien.c-types
io.encodings.utf8 alien.strings unix.types io.unix.files
io.encodings.utf8 alien.strings unix.types io.files.unix
io.files unix.statvfs.netbsd unix.getfsstat.netbsd arrays
grouping sequences io.encodings.utf8 specialized-arrays.direct.uint ;
IN: io.unix.files.netbsd
grouping sequences io.encodings.utf8
specialized-arrays.direct.uint io.files.info.unix ;
IN: io.files.info.unix.netbsd
TUPLE: netbsd-file-system-info < unix-file-system-info
blocks-reserved files-reserved

View File

@ -1,11 +1,11 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.strings alien.syntax
combinators io.backend io.files io.unix.files kernel math
combinators io.backend io.files io.files.unix kernel math
sequences system unix unix.getfsstat.openbsd grouping
unix.statfs.openbsd unix.statvfs.openbsd unix.types
specialized-arrays.direct.uint arrays ;
IN: io.unix.files.openbsd
specialized-arrays.direct.uint arrays io.files.info.unix ;
IN: io.files.unix.openbsd
TUPLE: freebsd-file-system-info < unix-file-system-info
io-size sync-writes sync-reads async-writes async-reads

View File

@ -1,80 +1,10 @@
! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman.
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: io.backend io.ports io.unix.backend io.files io
unix unix.stat unix.time kernel math continuations
math.bitwise byte-arrays alien combinators calendar
io.encodings.binary accessors sequences strings system
io.files.private destructors vocabs.loader calendar.unix
unix.stat alien.c-types arrays unix.users unix.groups
environment fry io.encodings.utf8 alien.strings
combinators.short-circuit ;
IN: io.unix.files
M: unix cwd ( -- path )
MAXPATHLEN [ <byte-array> ] keep getcwd
[ (io-error) ] unless* ;
M: unix cd ( path -- ) [ chdir ] unix-system-call drop ;
: read-flags O_RDONLY ; inline
: open-read ( path -- fd ) O_RDONLY file-mode open-file ;
M: unix (file-reader) ( path -- stream )
open-read <fd> init-fd <input-port> ;
: write-flags { O_WRONLY O_CREAT O_TRUNC } flags ; inline
: open-write ( path -- fd )
write-flags file-mode open-file ;
M: unix (file-writer) ( path -- stream )
open-write <fd> init-fd <output-port> ;
: append-flags { O_WRONLY O_APPEND O_CREAT } flags ; inline
: open-append ( path -- fd )
[
append-flags file-mode open-file |dispose
dup 0 SEEK_END lseek io-error
] with-destructors ;
M: unix (file-appender) ( path -- stream )
open-append <fd> init-fd <output-port> ;
: touch-mode ( -- n )
{ O_WRONLY O_APPEND O_CREAT O_EXCL } flags ; foldable
M: unix touch-file ( path -- )
normalize-path
dup exists? [ touch ] [
touch-mode file-mode open-file close-file
] if ;
M: unix move-file ( from to -- )
[ normalize-path ] bi@ rename io-error ;
M: unix delete-file ( path -- ) normalize-path unlink-file ;
M: unix make-directory ( path -- )
normalize-path OCT: 777 mkdir io-error ;
M: unix delete-directory ( path -- )
normalize-path rmdir io-error ;
: (copy-file) ( from to -- )
dup parent-directory make-directories
binary <file-writer> [
swap binary <file-reader> [
swap stream-copy
] with-disposal
] with-disposal ;
M: unix copy-file ( from to -- )
[ normalize-path ] bi@
[ (copy-file) ]
[ swap file-info permissions>> chmod io-error ]
2bi ;
USING: accessors kernel system math math.bitwise strings arrays
sequences combinators combinators.short-circuit alien.c-types
vocabs.loader calendar calendar.unix io.files.info io.backend
unix unix.stat unix.time unix.users unix.groups ;
IN: io.files.info.unix
TUPLE: unix-file-system-info < file-system-info
block-size preferred-block-size
@ -103,13 +33,10 @@ HOOK: statvfs>file-system-info os ( file-system-info statvfs -- file-system-info
M: unix statvfs>file-system-info drop ;
: file-system-calculations ( file-system-info -- file-system-info' )
{
[ dup [ blocks-available>> ] [ block-size>> ] bi * >>available-space drop ]
[ dup [ blocks-free>> ] [ block-size>> ] bi * >>free-space drop ]
[ dup [ blocks>> ] [ block-size>> ] bi * >>total-space drop ]
[ dup [ total-space>> ] [ free-space>> ] bi - >>used-space drop ]
[ ]
} cleave ;
dup [ blocks-available>> ] [ block-size>> ] bi * >>available-space
dup [ blocks-free>> ] [ block-size>> ] bi * >>free-space
dup [ blocks>> ] [ block-size>> ] bi * >>total-space
dup [ total-space>> ] [ free-space>> ] bi - >>used-space ;
M: unix file-system-info
normalize-path
@ -118,14 +45,6 @@ M: unix file-system-info
[ file-system-statvfs statvfs>file-system-info ] bi
file-system-calculations ;
os {
{ linux [ "io.unix.files.linux" require ] }
{ macosx [ "io.unix.files.macosx" require ] }
{ freebsd [ "io.unix.files.freebsd" require ] }
{ netbsd [ "io.unix.files.netbsd" require ] }
{ openbsd [ "io.unix.files.openbsd" require ] }
} case
TUPLE: unix-file-info < file-info uid gid dev ino
nlink rdev blocks blocksize ;
@ -141,12 +60,6 @@ M: unix file-info ( path -- info )
M: unix link-info ( path -- info )
normalize-path link-status stat>file-info ;
M: unix make-link ( path1 path2 -- )
normalize-path symlink io-error ;
M: unix read-link ( path -- path' )
normalize-path read-symbolic-link ;
M: unix new-file-info ( -- class ) unix-file-info new ;
M: unix stat>file-info ( stat -- file-info )
@ -183,36 +96,6 @@ M: unix stat>file-info ( stat -- file-info )
M: unix stat>type ( stat -- type )
stat-st_mode n>file-type ;
! Linux has no extra fields in its stat struct
os {
{ macosx [ "io.unix.files.bsd" require ] }
{ netbsd [ "io.unix.files.bsd" require ] }
{ openbsd [ "io.unix.files.bsd" require ] }
{ freebsd [ "io.unix.files.bsd" require ] }
{ linux [ ] }
} case
: with-unix-directory ( path quot -- )
[ opendir dup [ (io-error) ] unless ] dip
dupd curry swap '[ _ closedir io-error ] [ ] cleanup ; inline
: find-next-file ( DIR* -- byte-array )
"dirent" <c-object>
f <void*>
[ readdir_r 0 = [ (io-error) ] unless ] 2keep
*void* [ drop f ] unless ;
M: unix >directory-entry ( byte-array -- directory-entry )
[ dirent-d_name utf8 alien>string ]
[ dirent-d_type dirent-type>file-type ] bi directory-entry boa ;
M: unix (directory-entries) ( path -- seq )
[
'[ _ find-next-file dup ]
[ >directory-entry ]
[ drop ] produce
] with-unix-directory ;
<PRIVATE
: stat-mode ( path -- mode )
@ -367,5 +250,3 @@ M: string set-file-group ( path string -- )
: file-group-name ( path -- string )
file-group-id group-name ;
M: unix home "HOME" os-env ;

View File

@ -0,0 +1,26 @@
IN: io.files.links
HELP: make-link
{ $values { "target" "a path to the symbolic link's target" } { "symlink" "a path to new symbolic link" } }
{ $description "Creates a symbolic link." } ;
HELP: read-link
{ $values { "symlink" "a path to an existing symbolic link" } { "path" "the path pointed to by the symbolic link" } }
{ $description "Reads the symbolic link and returns its target path." } ;
HELP: copy-link
{ $values { "target" "a path to an existing symlink" } { "symlink" "a path to a new symbolic link" } }
{ $description "Copies a symbolic link without following the link." } ;
{ make-link read-link copy-link } related-words
ARTICLE: "io.files.links" "Symbolic links"
"Reading and creating links:"
{ $subsection read-link }
{ $subsection make-link }
"Copying links:"
{ $subsection copy-link }
"Not all operating systems support symbolic links."
{ $see-also link-info } ;
ABOUT: "io.files.links"

View File

@ -0,0 +1,10 @@
! Copyright (C) 2008 Slava Pestov, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
IN: io.files.links
HOOK: make-link io-backend ( target symlink -- )
HOOK: read-link io-backend ( symlink -- path )
: copy-link ( target symlink -- )
[ read-link ] dip make-link ;

View File

@ -0,0 +1,10 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: io.backend io.backend.unix system unix ;
IN: io.files.links.unix
M: unix make-link ( path1 path2 -- )
normalize-path symlink io-error ;
M: unix read-link ( path -- path' )
normalize-path read-symbolic-link ;

View File

@ -54,6 +54,6 @@ PRIVATE>
'[ _ with-directory ] [ delete-tree ] bi ; inline
{
{ [ os unix? ] [ "io.unix.files.unique" ] }
{ [ os windows? ] [ "io.windows.files.unique" ] }
{ [ os unix? ] [ "io.files.unique.unix" ] }
{ [ os windows? ] [ "io.files.unique.windows" ] }
} cond require

View File

@ -1,8 +1,8 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel io.ports io.unix.backend math.bitwise
USING: kernel io.ports io.backend.unix math.bitwise
unix system io.files.unique ;
IN: io.unix.files.unique
IN: io.files.unique.unix
: open-unique-flags ( -- flags )
{ O_RDWR O_CREAT O_EXCL } flags ;

View File

@ -1,7 +1,7 @@
USING: kernel system windows.kernel32 io.windows
io.windows.files io.ports windows destructors environment
USING: kernel system windows.kernel32 io.backend.windows
io.files.windows io.ports windows destructors environment
io.files.unique ;
IN: io.windows.files.unique
IN: io.files.unique.windows
M: windows touch-unique-file ( path -- )
GENERIC_WRITE CREATE_NEW 0 open-file dispose ;

View File

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license.
USING: classes help.markup help.syntax io.streams.string
strings math calendar io.files ;
IN: io.unix.files
IN: io.files.unix
HELP: file-group-id
{ $values
@ -90,12 +90,12 @@ HELP: set-file-permissions
{ "path" "a pathname string" } { "n" "an integer, interepreted as a string of bits" } }
{ $description "Sets the file permissions for a given file with the supplied Unix permissions integer. Supplying an octal number with " { $link POSTPONE: OCT: } " is recommended." }
{ $examples "Using the tradidional octal value:"
{ $unchecked-example "USING: io.unix.files kernel ;"
{ $unchecked-example "USING: io.files.unix kernel ;"
"\"resource:license.txt\" OCT: 755 set-file-permissions"
""
}
"Higher-level, setting named bits:"
{ $unchecked-example "USING: io.unix.files kernel math.bitwise ;"
{ $unchecked-example "USING: io.files.unix kernel math.bitwise ;"
"\"resource:license.txt\""
"{ USER-ALL GROUP-READ GROUP-EXECUTE OTHER-READ OTHER-EXECUTE }"
"flags set-file-permissions"
@ -268,10 +268,10 @@ ARTICLE: "unix-file-ids" "Unix file user and group ids"
{ $subsection set-file-group } ;
ARTICLE: "io.unix.files" "Unix file attributes"
"The " { $vocab-link "io.unix.files" } " vocabulary implements the Unix backend for opening files and provides a high-level way to set permissions, timestamps, and user and group ids for files."
ARTICLE: "io.files.unix" "Unix file attributes"
"The " { $vocab-link "io.files.unix" } " vocabulary implements the Unix backend for opening files and provides a high-level way to set permissions, timestamps, and user and group ids for files."
{ $subsection "unix-file-permissions" }
{ $subsection "unix-file-timestamps" }
{ $subsection "unix-file-ids" } ;
ABOUT: "io.unix.files"
ABOUT: "io.files.unix"

View File

@ -1,7 +1,7 @@
USING: tools.test io.files continuations kernel io.unix.files
USING: tools.test io.files continuations kernel io.files.unix
math.bitwise calendar accessors math.functions math unix.users
unix.groups arrays sequences ;
IN: io.unix.files.tests
IN: io.files.unix.tests
[ "/usr/libexec/" ] [ "/usr/libexec/awk/" parent-directory ] unit-test
[ "/etc/" ] [ "/etc/passwd" parent-directory ] unit-test

View File

@ -0,0 +1,40 @@
! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: unix byte-arrays kernel io.backend.unix math.bitwise
io.ports io.files io.files.private io.pathnames environment
destructors system ;
IN: io.files.unix
M: unix cwd ( -- path )
MAXPATHLEN [ <byte-array> ] keep getcwd
[ (io-error) ] unless* ;
M: unix cd ( path -- ) [ chdir ] unix-system-call drop ;
: read-flags O_RDONLY ; inline
: open-read ( path -- fd ) O_RDONLY file-mode open-file ;
M: unix (file-reader) ( path -- stream )
open-read <fd> init-fd <input-port> ;
: write-flags { O_WRONLY O_CREAT O_TRUNC } flags ; inline
: open-write ( path -- fd )
write-flags file-mode open-file ;
M: unix (file-writer) ( path -- stream )
open-write <fd> init-fd <output-port> ;
: append-flags { O_WRONLY O_APPEND O_CREAT } flags ; inline
: open-append ( path -- fd )
[
append-flags file-mode open-file |dispose
dup 0 SEEK_END lseek io-error
] with-destructors ;
M: unix (file-appender) ( path -- stream )
open-append <fd> init-fd <output-port> ;
M: unix home "HOME" os-env ;

View File

@ -1,12 +1,12 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types io.binary io.backend io.files io.buffers
io.encodings.utf16n io.ports io.windows kernel math splitting
io.encodings.utf16n io.ports io.backend.windows kernel math splitting
fry alien.strings windows windows.kernel32 windows.time calendar
combinators math.functions sequences namespaces make words
symbols system destructors accessors math.bitwise continuations
windows.errors arrays byte-arrays generalizations ;
IN: io.windows.files
IN: io.files.windows
: open-file ( path access-mode create-mode flags -- handle )
[

View File

@ -1,6 +1,6 @@
USING: io.files kernel tools.test io.backend
io.windows.nt.files splitting sequences ;
IN: io.windows.nt.files.tests
io.files.windows.nt splitting sequences ;
IN: io.files.windows.nt.tests
[ f ] [ "\\foo" absolute-path? ] unit-test
[ t ] [ "\\\\?\\c:\\foo" absolute-path? ] unit-test

View File

@ -1,11 +1,11 @@
USING: continuations destructors io.buffers io.files io.backend
io.timeouts io.ports io.files.private io.windows
io.windows.files io.windows.nt.backend io.encodings.utf16n
io.timeouts io.ports io.files.private io.backend.windows
io.files.windows io.backend.windows.nt io.encodings.utf16n
windows windows.kernel32 kernel libc math threads system
environment alien.c-types alien.arrays alien.strings sequences
combinators combinators.short-circuit ascii splitting alien
strings assocs namespaces make accessors tr ;
IN: io.windows.nt.files
IN: io.files.windows.nt
M: winnt cwd
MAX_UNICODE_PATH dup "ushort" <c-array>

Some files were not shown because too many files have changed in this diff Show More