fs/as-file fails on java.io.File args

Issue #8 resolved
Former user created an issue

If you have a real File, the calls to the internal fs/as-file will fail with an error like this:

java.lang.IllegalArgumentException: No matching method found: substring for class java.io.File

Here's a test to show the problem:

(deftest test-with-real-java-file
(is (file? (tempfile)))
(is (directory? (tempdir)))
(is (file? (java.io.File. (tempfile))))
(is (directory? (java.io.File. (tempdir)))))

A quick and dirty fix is to add a line to fs/as-file to handle non-strings.

(defn- as-file [path]
(= path "") (io/as-file "")
(= path ".") (io/as-file cwd)

;; FIX below
(not (string? path)) (io/as-file path)
;; end FIX

(= (.substring path 0 1) *separator*) (io/as-file path)
:else (io/as-file (join *cwd* path))))

A better fix is use io/as-file earlier and deal with the java.io.File to test for relative versus absolute. The test for the separator as the root makes sense on Unix, but not Windows.

Comments (1)

  1. Log in to comment