Skip to content

Commit

Permalink
exists? should never throw (#72)
Browse files Browse the repository at this point in the history
Co-authored-by: ikappaki <ikappaki@users.noreply.github.com>
  • Loading branch information
ikappaki and ikappaki committed Aug 21, 2022
1 parent 3b8010d commit 60aea91
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ For a list of breaking changes, check [here](#breaking-changes).
## Unreleased

- [#65](https://github.com/babashka/fs/issues/65): Explicitly support `:win-exts` option on `which` function ([@lread](https://github.com/lread))
- [clj-kondo#1782](https://github.com/clj-kondo/clj-kondo/issues/1782): `exists?` should never throw on illegal input path.

## v0.1.6

Expand Down
9 changes: 6 additions & 3 deletions src/babashka/fs.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@
"Returns true if f exists."
([f] (exists? f nil))
([f {:keys [:nofollow-links]}]
(Files/exists
(as-path f)
(->link-opts nofollow-links))))
(try
(Files/exists
(as-path f)
(->link-opts nofollow-links))
(catch Exception _e
false))))

;;;; End predicates

Expand Down
6 changes: 6 additions & 0 deletions test/babashka/fs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,9 @@
(deftest uri->path-test
(is (instance? java.nio.file.Path
(fs/path (.toURI (fs/file "."))))))

(deftest invalid-path
(testing "illegal windows path"
;; a `:` outside of the drive letter is illegal but should not
;; throw.
(is (= (fs/exists? "c:/123:456") false))))

0 comments on commit 60aea91

Please sign in to comment.