From e39783b10ab79b533e37d9ed5a7f46034266d69d Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Thu, 28 Feb 2008 12:46:01 -0600 Subject: [PATCH 01/15] unix: Refactor more things out of unix and into unix.stat unis.stat: Move some common code to unix.stat from unix.stat.linux and unix.stat.macosx --- extra/io/unix/files/files.factor | 3 +- extra/unix/stat/linux/32/32.factor | 27 ++---------- extra/unix/stat/linux/64/64.factor | 25 +---------- extra/unix/stat/macosx/macosx.factor | 23 ---------- extra/unix/stat/stat.factor | 56 +++++++++++++++++++++++- extra/unix/unix.factor | 64 +--------------------------- 6 files changed, 63 insertions(+), 135 deletions(-) diff --git a/extra/io/unix/files/files.factor b/extra/io/unix/files/files.factor index 6afbc33049..7b1c97abbe 100755 --- a/extra/io/unix/files/files.factor +++ b/extra/io/unix/files/files.factor @@ -1,8 +1,9 @@ ! Copyright (C) 2005, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: io.backend io.nonblocking io.unix.backend io.files io -unix kernel math continuations math.bitfields byte-arrays +unix unix.stat kernel math continuations math.bitfields byte-arrays alien ; + IN: io.unix.files M: unix-io cwd diff --git a/extra/unix/stat/linux/32/32.factor b/extra/unix/stat/linux/32/32.factor index 4525fd3879..ed53fab86b 100644 --- a/extra/unix/stat/linux/32/32.factor +++ b/extra/unix/stat/linux/32/32.factor @@ -24,31 +24,10 @@ C-STRUCT: stat { "ulong" "unused4" } { "ulong" "unused5" } ; +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + FUNCTION: int __xstat ( int ver, char* pathname, stat* buf ) ; FUNCTION: int __lxstat ( int ver, char* pathname, stat* buf ) ; : stat ( pathname buf -- int ) 3 -rot __xstat ; -: lstat ( pathname buf -- int ) 3 -rot __lxstat ; - -! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -: S_IFMT OCT: 170000 ; ! These bits determine file type. - -: S_IFDIR OCT: 40000 ; ! Directory. -: S_IFCHR OCT: 20000 ; ! Character device. -: S_IFBLK OCT: 60000 ; ! Block device. -: S_IFREG OCT: 100000 ; ! Regular file. -: S_IFIFO OCT: 010000 ; ! FIFO. -: S_IFLNK OCT: 120000 ; ! Symbolic link. -: S_IFSOCK OCT: 140000 ; ! Socket. - -: S_ISTYPE ( mode mask -- val ) >r S_IFMT bitand r> = ; - -: S_ISREG ( mode -- value ) S_IFREG S_ISTYPE ; -: S_ISDIR ( mode -- value ) S_IFDIR S_ISTYPE ; -: S_ISCHR ( mode -- value ) S_IFCHR S_ISTYPE ; -: S_ISBLK ( mode -- value ) S_IFBLK S_ISTYPE ; -: S_ISFIFO ( mode -- value ) S_IFIFO S_ISTYPE ; -: S_ISLNK ( mode -- value ) S_IFLNK S_ISTYPE ; -: S_ISSOCK ( mode -- value ) S_IFSOCK S_ISTYPE ; - +: lstat ( pathname buf -- int ) 3 -rot __lxstat ; \ No newline at end of file diff --git a/extra/unix/stat/linux/64/64.factor b/extra/unix/stat/linux/64/64.factor index 3281af91d5..be6ad1e3fc 100644 --- a/extra/unix/stat/linux/64/64.factor +++ b/extra/unix/stat/linux/64/64.factor @@ -28,27 +28,4 @@ FUNCTION: int __xstat ( int ver, char* pathname, stat* buf ) ; FUNCTION: int __lxstat ( int ver, char* pathname, stat* buf ) ; : stat ( pathname buf -- int ) 3 -rot __xstat ; -: lstat ( pathname buf -- int ) 3 -rot __lxstat ; - -! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -: S_IFMT OCT: 170000 ; ! These bits determine file type. - -: S_IFDIR OCT: 40000 ; ! Directory. -: S_IFCHR OCT: 20000 ; ! Character device. -: S_IFBLK OCT: 60000 ; ! Block device. -: S_IFREG OCT: 100000 ; ! Regular file. -: S_IFIFO OCT: 010000 ; ! FIFO. -: S_IFLNK OCT: 120000 ; ! Symbolic link. -: S_IFSOCK OCT: 140000 ; ! Socket. - -: S_ISTYPE ( mode mask -- val ) >r S_IFMT bitand r> = ; - -: S_ISREG ( mode -- value ) S_IFREG S_ISTYPE ; -: S_ISDIR ( mode -- value ) S_IFDIR S_ISTYPE ; -: S_ISCHR ( mode -- value ) S_IFCHR S_ISTYPE ; -: S_ISBLK ( mode -- value ) S_IFBLK S_ISTYPE ; -: S_ISFIFO ( mode -- value ) S_IFIFO S_ISTYPE ; -: S_ISLNK ( mode -- value ) S_IFLNK S_ISTYPE ; -: S_ISSOCK ( mode -- value ) S_IFSOCK S_ISTYPE ; - +: lstat ( pathname buf -- int ) 3 -rot __lxstat ; \ No newline at end of file diff --git a/extra/unix/stat/macosx/macosx.factor b/extra/unix/stat/macosx/macosx.factor index 170d70403c..1cb3994708 100644 --- a/extra/unix/stat/macosx/macosx.factor +++ b/extra/unix/stat/macosx/macosx.factor @@ -27,26 +27,3 @@ C-STRUCT: stat FUNCTION: int stat ( char* pathname, stat* buf ) ; FUNCTION: int lstat ( char* pathname, stat* buf ) ; - -! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -: S_IFMT OCT: 170000 ; ! These bits determine file type. - -: S_IFDIR OCT: 40000 ; ! Directory. -: S_IFCHR OCT: 20000 ; ! Character device. -: S_IFBLK OCT: 60000 ; ! Block device. -: S_IFREG OCT: 100000 ; ! Regular file. -: S_IFIFO OCT: 010000 ; ! FIFO. -: S_IFLNK OCT: 120000 ; ! Symbolic link. -: S_IFSOCK OCT: 140000 ; ! Socket. - -: S_ISTYPE ( mode mask -- val ) >r S_IFMT bitand r> = ; - -: S_ISREG ( mode -- value ) S_IFREG S_ISTYPE ; -: S_ISDIR ( mode -- value ) S_IFDIR S_ISTYPE ; -: S_ISCHR ( mode -- value ) S_IFCHR S_ISTYPE ; -: S_ISBLK ( mode -- value ) S_IFBLK S_ISTYPE ; -: S_ISFIFO ( mode -- value ) S_IFIFO S_ISTYPE ; -: S_ISLNK ( mode -- value ) S_IFLNK S_ISTYPE ; -: S_ISSOCK ( mode -- value ) S_IFSOCK S_ISTYPE ; - diff --git a/extra/unix/stat/stat.factor b/extra/unix/stat/stat.factor index a3165fe214..ca0736b6d4 100644 --- a/extra/unix/stat/stat.factor +++ b/extra/unix/stat/stat.factor @@ -1,8 +1,62 @@ -USING: system combinators vocabs.loader ; +USING: kernel system combinators alien.syntax math vocabs.loader ; IN: unix.stat +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +! File Types +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: S_IFMT OCT: 170000 ; ! These bits determine file type. + +: S_IFDIR OCT: 40000 ; ! Directory. +: S_IFCHR OCT: 20000 ; ! Character device. +: S_IFBLK OCT: 60000 ; ! Block device. +: S_IFREG OCT: 100000 ; ! Regular file. +: S_IFIFO OCT: 010000 ; ! FIFO. +: S_IFLNK OCT: 120000 ; ! Symbolic link. +: S_IFSOCK OCT: 140000 ; ! Socket. + +: S_ISTYPE ( mode mask -- val ) >r S_IFMT bitand r> = ; + +: S_ISREG ( mode -- value ) S_IFREG S_ISTYPE ; +: S_ISDIR ( mode -- value ) S_IFDIR S_ISTYPE ; +: S_ISCHR ( mode -- value ) S_IFCHR S_ISTYPE ; +: S_ISBLK ( mode -- value ) S_IFBLK S_ISTYPE ; +: S_ISFIFO ( mode -- value ) S_IFIFO S_ISTYPE ; +: S_ISLNK ( mode -- value ) S_IFLNK S_ISTYPE ; +: S_ISSOCK ( mode -- value ) S_IFSOCK S_ISTYPE ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +! File Access Permissions +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +! Read, write, execute/search by owner +: S_IRWXU OCT: 0000700 ; inline ! rwx mask owner +: S_IRUSR OCT: 0000400 ; inline ! r owner +: S_IWUSR OCT: 0000200 ; inline ! w owner +: S_IXUSR OCT: 0000100 ; inline ! x owner +! Read, write, execute/search by group +: S_IRWXG OCT: 0000070 ; inline ! rwx mask group +: S_IRGRP OCT: 0000040 ; inline ! r group +: S_IWGRP OCT: 0000020 ; inline ! w group +: S_IXGRP OCT: 0000010 ; inline ! x group +! Read, write, execute/search by others +: S_IRWXO OCT: 0000007 ; inline ! rwx mask other +: S_IROTH OCT: 0000004 ; inline ! r other +: S_IWOTH OCT: 0000002 ; inline ! w other +: S_IXOTH OCT: 0000001 ; inline ! x other + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +FUNCTION: int chmod ( char* path, mode_t mode ) ; + +FUNCTION: int fchmod ( int fd, mode_t mode ) ; + +FUNCTION: int mkdir ( char* path, mode_t mode ) ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + { { [ linux? ] [ "unix.stat.linux" require ] } { [ t ] [ ] } diff --git a/extra/unix/unix.factor b/extra/unix/unix.factor index 68e46eb2ae..f83120a96f 100755 --- a/extra/unix/unix.factor +++ b/extra/unix/unix.factor @@ -1,37 +1,15 @@ ! Copyright (C) 2005, 2007 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -IN: unix + USING: alien alien.c-types alien.syntax kernel libc structs math namespaces system combinators vocabs.loader unix.types ; -! ! ! Unix types +IN: unix -! TYPEDEF: long word -! TYPEDEF: ulong uword - -! TYPEDEF: long longword -! TYPEDEF: ulong ulongword - -! TYPEDEF: long ssize_t -! TYPEDEF: longword blksize_t -! TYPEDEF: longword blkcnt_t -! TYPEDEF: longlong quad_t -! TYPEDEF: ulonglong dev_t -! TYPEDEF: uint gid_t TYPEDEF: uint in_addr_t -! TYPEDEF: ulong ino_t -! TYPEDEF: int pid_t TYPEDEF: uint socklen_t TYPEDEF: uint time_t -! TYPEDEF: uint uid_t TYPEDEF: ulong size_t -! TYPEDEF: ulong u_long -! TYPEDEF: uint mode_t -! TYPEDEF: uword nlink_t -! TYPEDEF: void* caddr_t - -! TYPEDEF: ulong off_t -! TYPEDEF-IF: bsd? ulonglong off_t C-STRUCT: tm { "int" "sec" } ! Seconds: 0-59 (K&R says 0-61?) @@ -56,41 +34,6 @@ C-STRUCT: timespec [ set-timespec-nsec ] keep [ set-timespec-sec ] keep ; -! ! ! Unix constants - -! File type -: S_IFMT OCT: 0170000 ; inline ! type of file -: S_IFIFO OCT: 0010000 ; inline ! named pipe (fifo) -: S_IFCHR OCT: 0020000 ; inline ! character special -: S_IFDIR OCT: 0040000 ; inline ! directory -: S_IFBLK OCT: 0060000 ; inline ! block special -: S_IFREG OCT: 0100000 ; inline ! regular -: S_IFLNK OCT: 0120000 ; inline ! symbolic link -: S_IFSOCK OCT: 0140000 ; inline ! socket -: S_IFWHT OCT: 0160000 ; inline ! whiteout -: S_IFXATTR OCT: 0200000 ; inline ! extended attribute - -! File mode -! Read, write, execute/search by owner -: S_IRWXU OCT: 0000700 ; inline ! rwx mask owner -: S_IRUSR OCT: 0000400 ; inline ! r owner -: S_IWUSR OCT: 0000200 ; inline ! w owner -: S_IXUSR OCT: 0000100 ; inline ! x owner -! Read, write, execute/search by group -: S_IRWXG OCT: 0000070 ; inline ! rwx mask group -: S_IRGRP OCT: 0000040 ; inline ! r group -: S_IWGRP OCT: 0000020 ; inline ! w group -: S_IXGRP OCT: 0000010 ; inline ! x group -! Read, write, execute/search by others -: S_IRWXO OCT: 0000007 ; inline ! rwx mask other -: S_IROTH OCT: 0000004 ; inline ! r other -: S_IWOTH OCT: 0000002 ; inline ! w other -: S_IXOTH OCT: 0000001 ; inline ! x other - -: S_ISUID OCT: 0004000 ; inline ! set user id on execution -: S_ISGID OCT: 0002000 ; inline ! set group id on execution -: S_ISVTX OCT: 0001000 ; inline ! sticky bit - : PROT_NONE 0 ; inline : PROT_READ 1 ; inline : PROT_WRITE 2 ; inline @@ -113,7 +56,6 @@ LIBRARY: libc FUNCTION: int accept ( int s, void* sockaddr, socklen_t* socklen ) ; FUNCTION: int bind ( int s, void* name, socklen_t namelen ) ; FUNCTION: int chdir ( char* path ) ; -FUNCTION: int chmod ( char* path, mode_t mode ) ; FUNCTION: int chown ( char* path, uid_t owner, gid_t group ) ; FUNCTION: int chroot ( char* path ) ; FUNCTION: void close ( int fd ) ; @@ -124,7 +66,6 @@ FUNCTION: int execv ( char* path, char** argv ) ; FUNCTION: int execvp ( char* path, char** argv ) ; FUNCTION: int execve ( char* path, char** argv, char** envp ) ; FUNCTION: int fchdir ( int fd ) ; -FUNCTION: int fchmod ( int fd, mode_t mode ) ; FUNCTION: int fchown ( int fd, uid_t owner, gid_t group ) ; FUNCTION: int fcntl ( int fd, int cmd, int arg ) ; FUNCTION: int flock ( int fd, int operation ) ; @@ -150,7 +91,6 @@ FUNCTION: int lchown ( char* path, uid_t owner, gid_t group ) ; FUNCTION: int listen ( int s, int backlog ) ; FUNCTION: tm* localtime ( time_t* clock ) ; FUNCTION: off_t lseek ( int fildes, off_t offset, int whence ) ; -FUNCTION: int mkdir ( char* path, mode_t mode ) ; FUNCTION: void* mmap ( void* addr, size_t len, int prot, int flags, int fd, off_t offset ) ; FUNCTION: int munmap ( void* addr, size_t len ) ; FUNCTION: uint ntohl ( uint n ) ; From 48e305ee49a05aa66c0d23857b35c1fc17606a18 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 28 Feb 2008 15:42:07 -0600 Subject: [PATCH 02/15] add words for dealing with temporary files not tested on windows --- .../io/files/temporary/backend/backend.factor | 5 +++ extra/io/files/temporary/temporary.factor | 36 +++++++++++++++++++ .../io/unix/files/temporary/temporary.factor | 12 +++++++ .../windows/files/temporary/temporary.factor | 8 +++++ 4 files changed, 61 insertions(+) create mode 100644 extra/io/files/temporary/backend/backend.factor create mode 100644 extra/io/files/temporary/temporary.factor create mode 100644 extra/io/unix/files/temporary/temporary.factor create mode 100644 extra/io/windows/files/temporary/temporary.factor diff --git a/extra/io/files/temporary/backend/backend.factor b/extra/io/files/temporary/backend/backend.factor new file mode 100644 index 0000000000..0fe4068621 --- /dev/null +++ b/extra/io/files/temporary/backend/backend.factor @@ -0,0 +1,5 @@ +USING: io.backend ; +IN: io.files.temporary.backend + +HOOK: (temporary-file) io-backend ( path prefix suffix -- stream path ) +HOOK: temporary-path io-backend ( -- path ) diff --git a/extra/io/files/temporary/temporary.factor b/extra/io/files/temporary/temporary.factor new file mode 100644 index 0000000000..d46ddff8c6 --- /dev/null +++ b/extra/io/files/temporary/temporary.factor @@ -0,0 +1,36 @@ +USING: kernel math math.bitfields combinators.lib math.parser +random sequences sequences.lib continuations namespaces +io.files io.backend io.nonblocking io arrays +io.files.temporary.backend system combinators vocabs.loader ; +USE: tools.walker +IN: io.files.temporary + +: random-letter ( -- ch ) + 26 random { CHAR: a CHAR: A } random + ; + +: random-ch ( -- ch ) + { t f } random + [ 10 random CHAR: 0 + ] [ random-letter ] if ; + +: random-name ( n -- string ) + [ drop random-ch ] "" map-as ; + +: ( prefix suffix -- path duplex-stream ) + temporary-path -rot + [ 10 random-name swap 3append path+ dup (temporary-file) ] 3curry + 10 retry ; + +: with-temporary-file ( quot -- path ) + >r f f r> with-stream ; + +: temporary-directory ( -- path ) + [ temporary-path 10 random-name path+ dup make-directory ] 10 retry ; + +: with-temporary-directory ( quot -- ) + >r temporary-directory r> + [ with-directory ] 2keep drop delete-tree ; + +{ + { [ unix? ] [ "io.unix.files.temporary" ] } + { [ windows? ] [ "io.windows.files.temporary" ] } +} cond require diff --git a/extra/io/unix/files/temporary/temporary.factor b/extra/io/unix/files/temporary/temporary.factor new file mode 100644 index 0000000000..0ac6d7605e --- /dev/null +++ b/extra/io/unix/files/temporary/temporary.factor @@ -0,0 +1,12 @@ +USING: kernel io.nonblocking io.unix.backend math.bitfields +unix io.files.temporary.backend ; +IN: io.unix.files.temporary + +: open-temporary-flags ( -- flags ) + { O_RDWR O_CREAT O_EXCL } flags ; + +M: unix-io (temporary-file) ( path -- duplex-stream ) + open-temporary-flags file-mode open dup io-error + ; + +M: unix-io temporary-path ( -- path ) "/tmp" ; diff --git a/extra/io/windows/files/temporary/temporary.factor b/extra/io/windows/files/temporary/temporary.factor new file mode 100644 index 0000000000..d96ff49e15 --- /dev/null +++ b/extra/io/windows/files/temporary/temporary.factor @@ -0,0 +1,8 @@ +USING: kernel system ; +IN: io.windows.files.temporary + +M: windows-io (temporary-file) ( path -- stream ) + GENERIC_WRITE CREATE_NEW 0 open-file 0 ; + +M: windows-io temporary-path ( -- path ) + "TEMP" os-env ; From fbfa1f8de9be31a410ef4a6293c60fdbfb863914 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 28 Feb 2008 15:42:34 -0600 Subject: [PATCH 03/15] add retry combinator to combinators.lib --- extra/combinators/lib/lib.factor | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extra/combinators/lib/lib.factor b/extra/combinators/lib/lib.factor index 9ccada1ec1..019f4fe376 100755 --- a/extra/combinators/lib/lib.factor +++ b/extra/combinators/lib/lib.factor @@ -3,7 +3,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: kernel combinators namespaces quotations hashtables sequences assocs arrays inference effects math math.ranges -arrays.lib shuffle macros bake combinators.cleave ; +arrays.lib shuffle macros bake combinators.cleave +continuations ; IN: combinators.lib @@ -167,3 +168,6 @@ MACRO: construct-slots ( assoc tuple-class -- tuple ) : and? ( obj quot1 quot2 -- ? ) >r keep r> rot [ call ] [ 2drop f ] if ; inline + +: retry ( quot n -- ) + swap [ drop ] swap compose attempt-all ; From c9b73f062b2266466ea8d250b27a49e82ac6d9cb Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Thu, 28 Feb 2008 23:46:27 -0600 Subject: [PATCH 04/15] Implement file-info --- core/io/files/files.factor | 16 +++++++++++++++- extra/io/unix/files/files.factor | 25 +++++++++++++++++++++++-- extra/unix/stat/macosx/macosx.factor | 4 ++++ extra/unix/stat/stat.factor | 23 +++++++++++++++++------ 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/core/io/files/files.factor b/core/io/files/files.factor index 85f0621443..e20437fa85 100755 --- a/core/io/files/files.factor +++ b/core/io/files/files.factor @@ -1,10 +1,11 @@ ! Copyright (C) 2004, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -IN: io.files USING: io.backend io.files.private io hashtables kernel math memory namespaces sequences strings assocs arrays definitions system combinators splitting sbufs continuations ; +IN: io.files + ! Pathnames : path-separator? ( ch -- ? ) windows? "/\\" "/" ? member? ; @@ -50,6 +51,19 @@ TUPLE: no-parent-directory path ; { [ t ] [ drop ] } } cond ; +TUPLE: file-info type size permissions modified ; + +HOOK: file-info io-backend ( path -- info ) + +SYMBOL: +regular-file+ +SYMBOL: +directory+ +SYMBOL: +character-device+ +SYMBOL: +block-device+ +SYMBOL: +fifo+ +SYMBOL: +symbolic-link+ +SYMBOL: +socket+ +SYMBOL: +unknown+ + ! File metadata : stat ( path -- directory? permissions length modified ) normalize-pathname (stat) ; diff --git a/extra/io/unix/files/files.factor b/extra/io/unix/files/files.factor index 7b1c97abbe..a5a4e64c03 100755 --- a/extra/io/unix/files/files.factor +++ b/extra/io/unix/files/files.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2005, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: io.backend io.nonblocking io.unix.backend io.files io -unix unix.stat kernel math continuations math.bitfields byte-arrays -alien ; + unix unix.stat kernel math continuations math.bitfields byte-arrays + alien combinators combinators.cleave calendar ; IN: io.unix.files @@ -68,3 +68,24 @@ M: unix-io delete-directory ( path -- ) M: unix-io copy-file ( from to -- ) >r dup file-permissions over r> (copy-file) chmod io-error ; + +: stat>type ( stat -- type ) + stat-st_mode { + { [ dup S_ISREG ] [ +regular-file+ ] } + { [ dup S_ISDIR ] [ +directory+ ] } + { [ dup S_ISCHR ] [ +character-device+ ] } + { [ dup S_ISBLK ] [ +block-device+ ] } + { [ dup S_ISFIFO ] [ +fifo+ ] } + { [ dup S_ISLNK ] [ +symbolic-link+ ] } + { [ dup S_ISSOCK ] [ +socket+ ] } + { [ t ] [ +unknown+ ] } + } cond nip ; + +M: unix-io file-info ( path -- info ) + stat* { + [ stat>type ] + [ stat-st_size ] + [ stat-st_mode ] + [ stat-st_mtim timespec-sec seconds unix-1970 time+ ] + } cleave + \ file-info construct-boa ; diff --git a/extra/unix/stat/macosx/macosx.factor b/extra/unix/stat/macosx/macosx.factor index 1cb3994708..3741a22413 100644 --- a/extra/unix/stat/macosx/macosx.factor +++ b/extra/unix/stat/macosx/macosx.factor @@ -27,3 +27,7 @@ C-STRUCT: stat FUNCTION: int stat ( char* pathname, stat* buf ) ; FUNCTION: int lstat ( char* pathname, stat* buf ) ; + +: stat-st_atim stat-st_atimespec ; +: stat-st_mtim stat-st_mtimespec ; +: stat-st_ctim stat-st_ctimespec ; \ No newline at end of file diff --git a/extra/unix/stat/stat.factor b/extra/unix/stat/stat.factor index ca0736b6d4..204321f30c 100644 --- a/extra/unix/stat/stat.factor +++ b/extra/unix/stat/stat.factor @@ -1,5 +1,6 @@ -USING: kernel system combinators alien.syntax math vocabs.loader ; +USING: kernel system combinators alien.syntax alien.c-types + math io.unix.backend vocabs.loader ; IN: unix.stat @@ -55,11 +56,21 @@ FUNCTION: int fchmod ( int fd, mode_t mode ) ; FUNCTION: int mkdir ( char* path, mode_t mode ) ; +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +<< + os + { + { "linux" [ "unix.stat.linux" require ] } + { "macosx" [ "unix.stat.macosx" require ] } + [ drop ] + } + case +>> ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -{ - { [ linux? ] [ "unix.stat.linux" require ] } - { [ t ] [ ] } -} -cond +: check-status ( n -- ) io-error ; +: stat* ( pathname -- stat ) + "stat" dup >r + stat check-status + r> ; From 499948047a774ca676c20808a4ab147fe259e863 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 29 Feb 2008 00:10:37 -0600 Subject: [PATCH 05/15] rename io.files.temporary to io.files.unique write documentation --- .../io/files/temporary/backend/backend.factor | 5 -- extra/io/files/temporary/temporary.factor | 36 ------------- extra/io/files/unique/backend/backend.factor | 5 ++ extra/io/files/unique/unique-docs.factor | 50 +++++++++++++++++++ extra/io/files/unique/unique.factor | 48 ++++++++++++++++++ .../io/unix/files/temporary/temporary.factor | 12 ----- extra/io/unix/files/unique/unique.factor | 12 +++++ extra/io/unix/unix.factor | 4 +- .../temporary.factor => unique/unique.factor} | 4 +- extra/io/windows/windows.factor | 8 +-- 10 files changed, 123 insertions(+), 61 deletions(-) delete mode 100644 extra/io/files/temporary/backend/backend.factor delete mode 100644 extra/io/files/temporary/temporary.factor create mode 100644 extra/io/files/unique/backend/backend.factor create mode 100644 extra/io/files/unique/unique-docs.factor create mode 100644 extra/io/files/unique/unique.factor delete mode 100644 extra/io/unix/files/temporary/temporary.factor create mode 100644 extra/io/unix/files/unique/unique.factor rename extra/io/windows/files/{temporary/temporary.factor => unique/unique.factor} (63%) diff --git a/extra/io/files/temporary/backend/backend.factor b/extra/io/files/temporary/backend/backend.factor deleted file mode 100644 index 0fe4068621..0000000000 --- a/extra/io/files/temporary/backend/backend.factor +++ /dev/null @@ -1,5 +0,0 @@ -USING: io.backend ; -IN: io.files.temporary.backend - -HOOK: (temporary-file) io-backend ( path prefix suffix -- stream path ) -HOOK: temporary-path io-backend ( -- path ) diff --git a/extra/io/files/temporary/temporary.factor b/extra/io/files/temporary/temporary.factor deleted file mode 100644 index d46ddff8c6..0000000000 --- a/extra/io/files/temporary/temporary.factor +++ /dev/null @@ -1,36 +0,0 @@ -USING: kernel math math.bitfields combinators.lib math.parser -random sequences sequences.lib continuations namespaces -io.files io.backend io.nonblocking io arrays -io.files.temporary.backend system combinators vocabs.loader ; -USE: tools.walker -IN: io.files.temporary - -: random-letter ( -- ch ) - 26 random { CHAR: a CHAR: A } random + ; - -: random-ch ( -- ch ) - { t f } random - [ 10 random CHAR: 0 + ] [ random-letter ] if ; - -: random-name ( n -- string ) - [ drop random-ch ] "" map-as ; - -: ( prefix suffix -- path duplex-stream ) - temporary-path -rot - [ 10 random-name swap 3append path+ dup (temporary-file) ] 3curry - 10 retry ; - -: with-temporary-file ( quot -- path ) - >r f f r> with-stream ; - -: temporary-directory ( -- path ) - [ temporary-path 10 random-name path+ dup make-directory ] 10 retry ; - -: with-temporary-directory ( quot -- ) - >r temporary-directory r> - [ with-directory ] 2keep drop delete-tree ; - -{ - { [ unix? ] [ "io.unix.files.temporary" ] } - { [ windows? ] [ "io.windows.files.temporary" ] } -} cond require diff --git a/extra/io/files/unique/backend/backend.factor b/extra/io/files/unique/backend/backend.factor new file mode 100644 index 0000000000..228b6881f9 --- /dev/null +++ b/extra/io/files/unique/backend/backend.factor @@ -0,0 +1,5 @@ +USING: io.backend ; +IN: io.files.unique.backend + +HOOK: (make-unique-file) io-backend ( prefix suffix -- stream path ) +HOOK: temporary-path io-backend ( -- path ) diff --git a/extra/io/files/unique/unique-docs.factor b/extra/io/files/unique/unique-docs.factor new file mode 100644 index 0000000000..61f960d9f7 --- /dev/null +++ b/extra/io/files/unique/unique-docs.factor @@ -0,0 +1,50 @@ +USING: help.markup help.syntax io io.nonblocking kernel math +io.files.unique.private math.parser io.files ; +IN: io.files.unique + +ARTICLE: "unique" "Making and using unique files" +"Files:" +{ $subsection make-unique-file } +{ $subsection with-unique-file } +{ $subsection with-temporary-file } +"Directories:" +{ $subsection make-unique-directory } +{ $subsection with-unique-directory } +{ $subsection with-temporary-directory } ; + +ABOUT: "unique" + +HELP: make-unique-file ( prefix suffix -- path stream ) +{ $values { "prefix" "a string" } { "suffix" "a string" } +{ "path" "a pathname string" } { "stream" "an output stream" } } +{ $description "Creates a file that is guaranteed not to exist in a platform-specific temporary directory. The file name is composed of a prefix, a number of random digits and letters, and the suffix. Returns the full pathname and a " { $link } " stream." } +{ $errors "Throws an error if a new unique file cannot be created after a number of tries. Since each try generates a new random name, the most likely error is incorrect directory permissions on the temporary directory." } +{ $see-also with-unique-file } ; + +HELP: make-unique-directory ( -- path ) +{ $values { "path" "a pathname string" } } +{ $description "Creates a directory that is guaranteed not to exist in a platform-specific temporary directory and returns the full pathname." } +{ $errors "Throws an error if the directory cannot be created after a number of tries. Since each try generates a new random name, the most likely error is incorrect directory permissions on the temporary directory." } +{ $see-also with-unique-directory } ; + +HELP: with-unique-file ( quot -- path ) +{ $values { "quot" "a quotation" } { "path" "a pathname string" } } +{ $description "Creates a file with " { $link make-unique-file } " and calls " { $link with-stream } " on the newly created file. Returns the full pathname after the stream has been closed." } +{ $notes "The unique file will remain after calling this word." } +{ $see-also with-temporary-file } ; + +HELP: with-unique-directory ( quot -- path ) +{ $values { "quot" "a quotation" } { "path" "a pathname string" } } +{ $description "Creates a directory with " { $link make-unique-directory } " and calls " { $link with-directory } " on the newly created directory. Returns the full pathname after the quotation has been called." } +{ $notes "The directory will remain after calling this word." } +{ $see-also with-temporary-directory } ; + +HELP: with-temporary-file ( quot -- ) +{ $values { "quot" "a quotation" } } +{ $description "Creates a file with " { $link make-unique-file } " and calls " { $link with-stream } " on the newly created file. The file is deleted after the quotation returns." } +{ $see-also with-unique-file } ; + +HELP: with-temporary-directory ( quot -- ) +{ $values { "quot" "a quotation" } } +{ $description "Creates a directory with " { $link make-unique-directory } " and calls " { $link with-directory } " on the newly created directory. The directory is deleted after the quotation returns." } +{ $see-also with-unique-directory } ; diff --git a/extra/io/files/unique/unique.factor b/extra/io/files/unique/unique.factor new file mode 100644 index 0000000000..3a1c3c46b8 --- /dev/null +++ b/extra/io/files/unique/unique.factor @@ -0,0 +1,48 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: kernel math math.bitfields combinators.lib math.parser +random sequences sequences.lib continuations namespaces +io.files io.backend io.nonblocking io arrays +io.files.unique.backend system combinators vocabs.loader ; +IN: io.files.unique + + + +: make-unique-file ( prefix suffix -- path stream ) + temporary-path -rot + [ + unique-length random-name swap 3append path+ + dup (make-unique-file) + ] 3curry unique-retries retry ; + +: with-unique-file ( quot -- path ) + >r f f make-unique-file r> with-stream ; inline + +: with-temporary-file ( quot -- ) + with-unique-file delete-file ; inline + +: make-unique-directory ( -- path ) + [ + temporary-path unique-length random-name path+ + dup make-directory + ] unique-retries retry ; + +: with-unique-directory ( quot -- path ) + >r make-unique-directory r> + [ with-directory ] curry keep ; inline + +: with-temporary-directory ( quot -- ) + with-unique-directory delete-tree ; inline diff --git a/extra/io/unix/files/temporary/temporary.factor b/extra/io/unix/files/temporary/temporary.factor deleted file mode 100644 index 0ac6d7605e..0000000000 --- a/extra/io/unix/files/temporary/temporary.factor +++ /dev/null @@ -1,12 +0,0 @@ -USING: kernel io.nonblocking io.unix.backend math.bitfields -unix io.files.temporary.backend ; -IN: io.unix.files.temporary - -: open-temporary-flags ( -- flags ) - { O_RDWR O_CREAT O_EXCL } flags ; - -M: unix-io (temporary-file) ( path -- duplex-stream ) - open-temporary-flags file-mode open dup io-error - ; - -M: unix-io temporary-path ( -- path ) "/tmp" ; diff --git a/extra/io/unix/files/unique/unique.factor b/extra/io/unix/files/unique/unique.factor new file mode 100644 index 0000000000..185d9cd405 --- /dev/null +++ b/extra/io/unix/files/unique/unique.factor @@ -0,0 +1,12 @@ +USING: kernel io.nonblocking io.unix.backend math.bitfields +unix io.files.unique.backend ; +IN: io.unix.files.unique + +: open-unique-flags ( -- flags ) + { O_RDWR O_CREAT O_EXCL } flags ; + +M: unix-io (make-unique-file) ( path -- duplex-stream ) + open-unique-flags file-mode open dup io-error + ; + +M: unix-io temporary-path ( -- path ) "/tmp" ; diff --git a/extra/io/unix/unix.factor b/extra/io/unix/unix.factor index e740561cf9..a328a3baf4 100755 --- a/extra/io/unix/unix.factor +++ b/extra/io/unix/unix.factor @@ -1,6 +1,6 @@ USING: io.unix.backend io.unix.files io.unix.sockets io.timeouts -io.unix.launcher io.unix.mmap io.backend combinators namespaces -system vocabs.loader sequences ; +io.unix.launcher io.unix.mmap io.backend io.files.temporary +combinators namespaces system vocabs.loader sequences ; "io.unix." os append require diff --git a/extra/io/windows/files/temporary/temporary.factor b/extra/io/windows/files/unique/unique.factor similarity index 63% rename from extra/io/windows/files/temporary/temporary.factor rename to extra/io/windows/files/unique/unique.factor index d96ff49e15..01e654751e 100644 --- a/extra/io/windows/files/temporary/temporary.factor +++ b/extra/io/windows/files/unique/unique.factor @@ -1,7 +1,7 @@ USING: kernel system ; -IN: io.windows.files.temporary +IN: io.windows.files.unique -M: windows-io (temporary-file) ( path -- stream ) +M: windows-io (make-unique-file) ( path -- stream ) GENERIC_WRITE CREATE_NEW 0 open-file 0 ; M: windows-io temporary-path ( -- path ) diff --git a/extra/io/windows/windows.factor b/extra/io/windows/windows.factor index 9f2f2db0a5..2c2ad66221 100755 --- a/extra/io/windows/windows.factor +++ b/extra/io/windows/windows.factor @@ -2,10 +2,10 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types arrays destructors io io.backend io.buffers io.files io.nonblocking io.sockets io.binary -io.sockets.impl windows.errors strings io.streams.duplex kernel -math namespaces sequences windows windows.kernel32 -windows.shell32 windows.types windows.winsock splitting -continuations math.bitfields ; +io.sockets.impl io.windows.files.temporary windows.errors +strings io.streams.duplex kernel math namespaces sequences +windows windows.kernel32 windows.shell32 windows.types +windows.winsock splitting continuations math.bitfields ; IN: io.windows TUPLE: windows-nt-io ; From edcda314bd2a6a89ed39d4c81acff182a0af0f0b Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 29 Feb 2008 00:11:01 -0600 Subject: [PATCH 06/15] add temporary files to docs --- core/io/files/files-docs.factor | 1 + 1 file changed, 1 insertion(+) diff --git a/core/io/files/files-docs.factor b/core/io/files/files-docs.factor index c918641912..b8cf747106 100755 --- a/core/io/files/files-docs.factor +++ b/core/io/files/files-docs.factor @@ -87,6 +87,7 @@ ARTICLE: "io.files" "Basic file operations" { $subsection "fs-meta" } { $subsection "directories" } { $subsection "delete-move-copy" } +{ $subsection "unique" } { $see-also "os" } ; ABOUT: "io.files" From 0102689b1e0cf6bc062f76a62c77498c6dd0159b Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 29 Feb 2008 00:11:50 -0600 Subject: [PATCH 07/15] make retry inline --- extra/combinators/lib/lib.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/combinators/lib/lib.factor b/extra/combinators/lib/lib.factor index 019f4fe376..08336fd32e 100755 --- a/extra/combinators/lib/lib.factor +++ b/extra/combinators/lib/lib.factor @@ -170,4 +170,4 @@ MACRO: construct-slots ( assoc tuple-class -- tuple ) >r keep r> rot [ call ] [ 2drop f ] if ; inline : retry ( quot n -- ) - swap [ drop ] swap compose attempt-all ; + swap [ drop ] swap compose attempt-all ; inline From ad2d06806b16d38ac48bc56d110065cf4b2b42a2 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 29 Feb 2008 00:55:24 -0600 Subject: [PATCH 08/15] s/temporary/unique/ --- extra/io/unix/unix.factor | 2 +- extra/io/windows/windows.factor | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extra/io/unix/unix.factor b/extra/io/unix/unix.factor index a328a3baf4..11cdc0aa3b 100755 --- a/extra/io/unix/unix.factor +++ b/extra/io/unix/unix.factor @@ -1,5 +1,5 @@ USING: io.unix.backend io.unix.files io.unix.sockets io.timeouts -io.unix.launcher io.unix.mmap io.backend io.files.temporary +io.unix.launcher io.unix.mmap io.backend io.files.unique combinators namespaces system vocabs.loader sequences ; "io.unix." os append require diff --git a/extra/io/windows/windows.factor b/extra/io/windows/windows.factor index 2c2ad66221..06dbaf89f7 100755 --- a/extra/io/windows/windows.factor +++ b/extra/io/windows/windows.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types arrays destructors io io.backend io.buffers io.files io.nonblocking io.sockets io.binary -io.sockets.impl io.windows.files.temporary windows.errors +io.sockets.impl io.windows.files.unique windows.errors strings io.streams.duplex kernel math namespaces sequences windows windows.kernel32 windows.shell32 windows.types windows.winsock splitting continuations math.bitfields ; From 869cfd54630a7259dfdab9d17e50aaefec6b36d8 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 29 Feb 2008 15:38:20 -0600 Subject: [PATCH 09/15] fix sqlite -- wasn't settin gthe bound? flag --- extra/db/sqlite/sqlite.factor | 3 ++- extra/db/tuples/tuples-tests.factor | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/extra/db/sqlite/sqlite.factor b/extra/db/sqlite/sqlite.factor index b980e99718..d873e98a95 100755 --- a/extra/db/sqlite/sqlite.factor +++ b/extra/db/sqlite/sqlite.factor @@ -64,7 +64,8 @@ M: sqlite-statement bind-tuple ( tuple statement -- ) [ sql-spec-type ] tri 3array ] with map ] keep - [ set-statement-bind-params ] keep bind-statement* ; + [ set-statement-bind-params ] keep + t over set-statement-bound? bind-statement* ; : last-insert-id ( -- id ) db get db-handle sqlite3_last_insert_rowid diff --git a/extra/db/tuples/tuples-tests.factor b/extra/db/tuples/tuples-tests.factor index c9e6d302e0..ade18286b4 100755 --- a/extra/db/tuples/tuples-tests.factor +++ b/extra/db/tuples/tuples-tests.factor @@ -81,7 +81,7 @@ person "PERSON" 1 "billy" 10 3.14 the-person1 set 2 "johnny" 10 3.14 the-person2 set -test-sqlite +! test-sqlite ! test-postgresql TUPLE: paste n summary author channel mode contents timestamp annotations ; From 93a8cbcac3fb462ade75625c8347c01c9b20f2a9 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 29 Feb 2008 15:41:54 -0600 Subject: [PATCH 10/15] fix a hack. oops --- extra/db/sqlite/sqlite.factor | 6 +++--- extra/db/tuples/tuples-tests.factor | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extra/db/sqlite/sqlite.factor b/extra/db/sqlite/sqlite.factor index d873e98a95..c03496530b 100755 --- a/extra/db/sqlite/sqlite.factor +++ b/extra/db/sqlite/sqlite.factor @@ -53,7 +53,8 @@ M: sqlite-result-set dispose ( result-set -- ) M: sqlite-statement bind-statement* ( statement -- ) dup statement-bound? [ dup reset-statement ] when - [ statement-bind-params ] [ statement-handle ] bi sqlite-bind ; + [ statement-bind-params ] [ statement-handle ] bi + sqlite-bind ; M: sqlite-statement bind-tuple ( tuple statement -- ) [ @@ -64,8 +65,7 @@ M: sqlite-statement bind-tuple ( tuple statement -- ) [ sql-spec-type ] tri 3array ] with map ] keep - [ set-statement-bind-params ] keep - t over set-statement-bound? bind-statement* ; + bind-statement ; : last-insert-id ( -- id ) db get db-handle sqlite3_last_insert_rowid diff --git a/extra/db/tuples/tuples-tests.factor b/extra/db/tuples/tuples-tests.factor index ade18286b4..c9e6d302e0 100755 --- a/extra/db/tuples/tuples-tests.factor +++ b/extra/db/tuples/tuples-tests.factor @@ -81,7 +81,7 @@ person "PERSON" 1 "billy" 10 3.14 the-person1 set 2 "johnny" 10 3.14 the-person2 set -! test-sqlite +test-sqlite ! test-postgresql TUPLE: paste n summary author channel mode contents timestamp annotations ; From b7f9aac2106499deeb65db76d9977e3ac87200b8 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 29 Feb 2008 17:10:22 -0600 Subject: [PATCH 11/15] fix with-unique-file --- extra/io/files/unique/unique.factor | 2 +- extra/io/unix/unix.factor | 2 +- extra/io/windows/files/unique/unique.factor | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extra/io/files/unique/unique.factor b/extra/io/files/unique/unique.factor index 3a1c3c46b8..b39a14c7f5 100644 --- a/extra/io/files/unique/unique.factor +++ b/extra/io/files/unique/unique.factor @@ -29,7 +29,7 @@ PRIVATE> ] 3curry unique-retries retry ; : with-unique-file ( quot -- path ) - >r f f make-unique-file r> with-stream ; inline + >r f f make-unique-file r> rot [ with-stream ] dip ; inline : with-temporary-file ( quot -- ) with-unique-file delete-file ; inline diff --git a/extra/io/unix/unix.factor b/extra/io/unix/unix.factor index 11cdc0aa3b..b7111c5eac 100755 --- a/extra/io/unix/unix.factor +++ b/extra/io/unix/unix.factor @@ -1,5 +1,5 @@ USING: io.unix.backend io.unix.files io.unix.sockets io.timeouts -io.unix.launcher io.unix.mmap io.backend io.files.unique +io.unix.launcher io.unix.mmap io.backend io.unix.files.unique combinators namespaces system vocabs.loader sequences ; "io.unix." os append require diff --git a/extra/io/windows/files/unique/unique.factor b/extra/io/windows/files/unique/unique.factor index 01e654751e..5f11bf6142 100644 --- a/extra/io/windows/files/unique/unique.factor +++ b/extra/io/windows/files/unique/unique.factor @@ -1,4 +1,4 @@ -USING: kernel system ; +USING: kernel system io.files.unqiue io.files.unique.backend ; IN: io.windows.files.unique M: windows-io (make-unique-file) ( path -- stream ) From ac6c91d5a626e7a47d9e23833131350d38e5f8e5 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 29 Feb 2008 17:44:53 -0600 Subject: [PATCH 12/15] fix bootstrap --- extra/io/files/unique/unique.factor | 5 +++++ extra/io/unix/unix.factor | 2 +- extra/io/windows/files/unique/unique.factor | 2 +- extra/io/windows/windows.factor | 8 ++++---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/extra/io/files/unique/unique.factor b/extra/io/files/unique/unique.factor index b39a14c7f5..1e77cd6814 100644 --- a/extra/io/files/unique/unique.factor +++ b/extra/io/files/unique/unique.factor @@ -46,3 +46,8 @@ PRIVATE> : with-temporary-directory ( quot -- ) with-unique-directory delete-tree ; inline + +{ + { [ unix? ] [ "io.unix.files.unique" ] } + { [ windows? ] [ "io.windows.files.unique" ] } +} cond require diff --git a/extra/io/unix/unix.factor b/extra/io/unix/unix.factor index b7111c5eac..64e2cc3c3d 100755 --- a/extra/io/unix/unix.factor +++ b/extra/io/unix/unix.factor @@ -1,5 +1,5 @@ USING: io.unix.backend io.unix.files io.unix.sockets io.timeouts -io.unix.launcher io.unix.mmap io.backend io.unix.files.unique +io.unix.launcher io.unix.mmap io.backend combinators namespaces system vocabs.loader sequences ; "io.unix." os append require diff --git a/extra/io/windows/files/unique/unique.factor b/extra/io/windows/files/unique/unique.factor index 5f11bf6142..ae06090488 100644 --- a/extra/io/windows/files/unique/unique.factor +++ b/extra/io/windows/files/unique/unique.factor @@ -1,4 +1,4 @@ -USING: kernel system io.files.unqiue io.files.unique.backend ; +USING: kernel system io.files.unique.backend ; IN: io.windows.files.unique M: windows-io (make-unique-file) ( path -- stream ) diff --git a/extra/io/windows/windows.factor b/extra/io/windows/windows.factor index 06dbaf89f7..38b7d4829c 100755 --- a/extra/io/windows/windows.factor +++ b/extra/io/windows/windows.factor @@ -2,10 +2,10 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types arrays destructors io io.backend io.buffers io.files io.nonblocking io.sockets io.binary -io.sockets.impl io.windows.files.unique windows.errors -strings io.streams.duplex kernel math namespaces sequences -windows windows.kernel32 windows.shell32 windows.types -windows.winsock splitting continuations math.bitfields ; +io.sockets.impl windows.errors strings io.streams.duplex +kernel math namespaces sequences windows windows.kernel32 +windows.shell32 windows.types windows.winsock splitting +continuations math.bitfields ; IN: io.windows TUPLE: windows-nt-io ; From adf5cfda5904f5f655016f1ea77bc287203d3ed8 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 29 Feb 2008 18:04:09 -0600 Subject: [PATCH 13/15] clean up retry --- extra/combinators/lib/lib.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/combinators/lib/lib.factor b/extra/combinators/lib/lib.factor index 08336fd32e..f65b94dc11 100755 --- a/extra/combinators/lib/lib.factor +++ b/extra/combinators/lib/lib.factor @@ -170,4 +170,4 @@ MACRO: construct-slots ( assoc tuple-class -- tuple ) >r keep r> rot [ call ] [ 2drop f ] if ; inline : retry ( quot n -- ) - swap [ drop ] swap compose attempt-all ; inline + [ drop ] rot compose attempt-all ; inline From 4f40f10b88fac030bd3a7cc9773589251c1c4e04 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 29 Feb 2008 18:04:20 -0600 Subject: [PATCH 14/15] fix stack effect --- extra/io/files/unique/backend/backend.factor | 2 +- extra/io/files/unique/unique.factor | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/extra/io/files/unique/backend/backend.factor b/extra/io/files/unique/backend/backend.factor index 228b6881f9..b26557688b 100644 --- a/extra/io/files/unique/backend/backend.factor +++ b/extra/io/files/unique/backend/backend.factor @@ -1,5 +1,5 @@ USING: io.backend ; IN: io.files.unique.backend -HOOK: (make-unique-file) io-backend ( prefix suffix -- stream path ) +HOOK: (make-unique-file) io-backend ( path -- stream ) HOOK: temporary-path io-backend ( -- path ) diff --git a/extra/io/files/unique/unique.factor b/extra/io/files/unique/unique.factor index 1e77cd6814..8c0666161e 100644 --- a/extra/io/files/unique/unique.factor +++ b/extra/io/files/unique/unique.factor @@ -22,11 +22,12 @@ IN: io.files.unique PRIVATE> : make-unique-file ( prefix suffix -- path stream ) +break temporary-path -rot [ unique-length random-name swap 3append path+ dup (make-unique-file) - ] 3curry unique-retries retry ; + ] 3curry unique-retries retry break ; : with-unique-file ( quot -- path ) >r f f make-unique-file r> rot [ with-stream ] dip ; inline From 2dffb31e53b18270cc5d5c686f9f997a3c8c0d7c Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 29 Feb 2008 18:05:38 -0600 Subject: [PATCH 15/15] remove debug info --- extra/io/files/unique/unique.factor | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extra/io/files/unique/unique.factor b/extra/io/files/unique/unique.factor index 8c0666161e..1e77cd6814 100644 --- a/extra/io/files/unique/unique.factor +++ b/extra/io/files/unique/unique.factor @@ -22,12 +22,11 @@ IN: io.files.unique PRIVATE> : make-unique-file ( prefix suffix -- path stream ) -break temporary-path -rot [ unique-length random-name swap 3append path+ dup (make-unique-file) - ] 3curry unique-retries retry break ; + ] 3curry unique-retries retry ; : with-unique-file ( quot -- path ) >r f f make-unique-file r> rot [ with-stream ] dip ; inline