From 22dd6a74b622488e58824c408437bcc11464c1d6 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 8 Dec 2008 12:46:44 -0600 Subject: [PATCH 1/4] add a unit test for tools.files --- basis/tools/files/files-tests.factor | 3 +++ basis/tools/files/files.factor | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/basis/tools/files/files-tests.factor b/basis/tools/files/files-tests.factor index 6aa68d8127..4dc4ef23f0 100644 --- a/basis/tools/files/files-tests.factor +++ b/basis/tools/files/files-tests.factor @@ -6,3 +6,6 @@ IN: tools.files.tests \ directory. must-infer [ ] [ "" directory. ] unit-test + +[ ] +[ { device-name free-space used-space total-space percent-used } file-systems. ] unit-test diff --git a/basis/tools/files/files.factor b/basis/tools/files/files.factor index 18baedae0a..db49dcbf61 100755 --- a/basis/tools/files/files.factor +++ b/basis/tools/files/files.factor @@ -65,5 +65,3 @@ percent-used percent-free ; { [ os unix? ] [ "tools.files.unix" ] } { [ os windows? ] [ "tools.files.windows" ] } } cond require - -! { device-name free-space used-space total-space percent-used } file-systems. From 971a6c89beac976ad8a90e7ff87df33133413c5c Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 8 Dec 2008 21:31:41 -0600 Subject: [PATCH 2/4] move io.paths from extra to basis --- {extra => basis}/io/paths/authors.txt | 0 {extra => basis}/io/paths/paths.factor | 2 +- {extra => basis}/io/paths/windows/authors.txt | 0 {extra => basis}/io/paths/windows/tags.txt | 0 {extra => basis}/io/paths/windows/windows.factor | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename {extra => basis}/io/paths/authors.txt (100%) rename {extra => basis}/io/paths/paths.factor (96%) rename {extra => basis}/io/paths/windows/authors.txt (100%) rename {extra => basis}/io/paths/windows/tags.txt (100%) rename {extra => basis}/io/paths/windows/windows.factor (100%) diff --git a/extra/io/paths/authors.txt b/basis/io/paths/authors.txt similarity index 100% rename from extra/io/paths/authors.txt rename to basis/io/paths/authors.txt diff --git a/extra/io/paths/paths.factor b/basis/io/paths/paths.factor similarity index 96% rename from extra/io/paths/paths.factor rename to basis/io/paths/paths.factor index 75d08b60f8..212ba9e396 100755 --- a/extra/io/paths/paths.factor +++ b/basis/io/paths/paths.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays deques dlists io.files io.paths.private +USING: accessors arrays deques dlists io.files kernel sequences system vocabs.loader fry continuations ; IN: io.paths diff --git a/extra/io/paths/windows/authors.txt b/basis/io/paths/windows/authors.txt similarity index 100% rename from extra/io/paths/windows/authors.txt rename to basis/io/paths/windows/authors.txt diff --git a/extra/io/paths/windows/tags.txt b/basis/io/paths/windows/tags.txt similarity index 100% rename from extra/io/paths/windows/tags.txt rename to basis/io/paths/windows/tags.txt diff --git a/extra/io/paths/windows/windows.factor b/basis/io/paths/windows/windows.factor similarity index 100% rename from extra/io/paths/windows/windows.factor rename to basis/io/paths/windows/windows.factor From 101bc66b2b16d65fc16c576efafcf0e32b7f6553 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 8 Dec 2008 21:32:19 -0600 Subject: [PATCH 3/4] add a unit test to io.paths --- basis/io/paths/paths-tests.factor | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 basis/io/paths/paths-tests.factor diff --git a/basis/io/paths/paths-tests.factor b/basis/io/paths/paths-tests.factor new file mode 100644 index 0000000000..01763ce5c0 --- /dev/null +++ b/basis/io/paths/paths-tests.factor @@ -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 From 154bc260c637c0c3670ad061648fc99243fdb076 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 8 Dec 2008 21:32:36 -0600 Subject: [PATCH 4/4] remove io.files.unique.backend rename (make-unique-file) to touch-unique-file --- basis/io/files/unique/backend/backend.factor | 5 ---- basis/io/files/unique/unique.factor | 25 +++++++++++++------- basis/io/unix/files/unique/unique.factor | 4 ++-- basis/io/windows/files/unique/unique.factor | 8 +++---- 4 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 basis/io/files/unique/backend/backend.factor diff --git a/basis/io/files/unique/backend/backend.factor b/basis/io/files/unique/backend/backend.factor deleted file mode 100644 index 7b9809fa28..0000000000 --- a/basis/io/files/unique/backend/backend.factor +++ /dev/null @@ -1,5 +0,0 @@ -USING: io.backend ; -IN: io.files.unique.backend - -HOOK: (make-unique-file) io-backend ( path -- ) -HOOK: temporary-path io-backend ( -- path ) diff --git a/basis/io/files/unique/unique.factor b/basis/io/files/unique/unique.factor index ec89517bbc..66540fb48e 100644 --- a/basis/io/files/unique/unique.factor +++ b/basis/io/files/unique/unique.factor @@ -1,11 +1,13 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel math math.bitwise math.parser -random sequences continuations namespaces -io.files io arrays io.files.unique.backend system -combinators vocabs.loader fry ; +USING: kernel math math.bitwise math.parser random sequences +continuations namespaces io.files io arrays system +combinators vocabs.loader fry io.backend ; IN: io.files.unique +HOOK: touch-unique-file io-backend ( path -- ) +HOOK: temporary-path io-backend ( -- path ) + SYMBOL: unique-length SYMBOL: unique-retries @@ -26,12 +28,17 @@ SYMBOL: unique-retries PRIVATE> +: (make-unique-file) ( path prefix suffix -- path ) + '[ + _ _ _ unique-length get random-name glue append-path + dup touch-unique-file + ] unique-retries get retry ; + : make-unique-file ( prefix suffix -- path ) - temporary-path -rot - [ - unique-length get random-name glue append-path - dup (make-unique-file) - ] 3curry unique-retries get retry ; + [ temporary-path ] 2dip (make-unique-file) ; + +: make-unique-file* ( prefix suffix -- path ) + [ current-directory get ] 2dip (make-unique-file) ; : with-unique-file ( prefix suffix quot: ( path -- ) -- ) [ make-unique-file ] dip [ delete-file ] bi ; inline diff --git a/basis/io/unix/files/unique/unique.factor b/basis/io/unix/files/unique/unique.factor index e47ac6a2e3..24dcdcb65a 100644 --- a/basis/io/unix/files/unique/unique.factor +++ b/basis/io/unix/files/unique/unique.factor @@ -1,13 +1,13 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: kernel io.ports io.unix.backend math.bitwise -unix io.files.unique.backend system ; +unix system io.files.unique ; IN: io.unix.files.unique : open-unique-flags ( -- flags ) { O_RDWR O_CREAT O_EXCL } flags ; -M: unix (make-unique-file) ( path -- ) +M: unix touch-unique-file ( path -- ) open-unique-flags file-mode open-file close-file ; M: unix temporary-path ( -- path ) "/tmp" ; diff --git a/basis/io/windows/files/unique/unique.factor b/basis/io/windows/files/unique/unique.factor index b1bf2bdc1c..ab99bf2cac 100644 --- a/basis/io/windows/files/unique/unique.factor +++ b/basis/io/windows/files/unique/unique.factor @@ -1,9 +1,9 @@ -USING: kernel system io.files.unique.backend -windows.kernel32 io.windows io.windows.files io.ports windows -destructors environment ; +USING: kernel system windows.kernel32 io.windows +io.windows.files io.ports windows destructors environment +io.files.unique ; IN: io.windows.files.unique -M: windows (make-unique-file) ( path -- ) +M: windows touch-unique-file ( path -- ) GENERIC_WRITE CREATE_NEW 0 open-file dispose ; M: windows temporary-path ( -- path )