diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2010-05-13 22:41:59 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-05-20 21:25:19 -0400 |
commit | 56dd2cd8714e30d85a215d520b0248f4783fbbbd (patch) | |
tree | 5a87684d6df05e6ac15cc7a604a58da995329688 | |
parent | 65b7e698c508658b6e2af1dedca999649c0f1f56 (diff) |
more code review of #311
- better docstring
- so long dangerous recursive delete, we hardly knew ye
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r-- | src/clj/clojure/java/io.clj | 15 | ||||
-rw-r--r-- | test/clojure/test_clojure/java/io.clj | 7 |
2 files changed, 7 insertions, 15 deletions
diff --git a/src/clj/clojure/java/io.clj b/src/clj/clojure/java/io.clj index ec2404f8..97ae4e3e 100644 --- a/src/clj/clojure/java/io.clj +++ b/src/clj/clojure/java/io.clj @@ -412,20 +412,9 @@ silently (throw (java.io.IOException. (str "Couldn't delete " f))))) -(defn delete-file-recursively - "Delete file f. If it's a directory, recursively delete all its contents. - Raise an exception if any deletion fails unless silently is true." - {:added "1.2"} - [f & [silently]] - (let [f (file f)] - (if (.isDirectory f) - (doseq [child (.listFiles f)] - (delete-file-recursively child silently))) - (delete-file f silently))) - (defn make-parents - "Create all parent directories of file. Pass extra args - as you would to file." + "Given the same arg(s) as for file, creates all parent directories of + the file they represent." {:added "1.2"} [f & more] (.mkdirs (.getParentFile ^File (apply file f more)))) diff --git a/test/clojure/test_clojure/java/io.clj b/test/clojure/test_clojure/java/io.clj index 1841ada0..d193942d 100644 --- a/test/clojure/test_clojure/java/io.clj +++ b/test/clojure/test_clojure/java/io.clj @@ -178,8 +178,11 @@ (deftest test-make-parents (let [tmp (System/getProperty "java.io.tmpdir")] - (delete-file-recursively (file tmp "test-make-parents") :silently) + (delete-file (file tmp "test-make-parents" "child" "grandchild") :silently) + (delete-file (file tmp "test-make-parents" "child") :silently) + (delete-file (file tmp "test-make-parents") :silently) (make-parents tmp "test-make-parents" "child" "grandchild") (is (.isDirectory (file tmp "test-make-parents" "child"))) (is (not (.isDirectory (file tmp "test-make-parents" "child" "grandchild")))) - (delete-file-recursively (file tmp "test-make-parents")))) + (delete-file (file tmp "test-make-parents" "child")) + (delete-file (file tmp "test-make-parents")))) |