-
-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore non file URLs when checking for directory or file extensions #83
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,16 +20,27 @@ | |
[] | ||
(not (nil? (boot-fake-classpath)))) | ||
|
||
(defn url? | ||
"Check whether the argument is an url" | ||
[u] | ||
(instance? java.net.URL u)) | ||
|
||
(defn directory? | ||
"Whether the argument is a directory" | ||
"Whether the argument is a directory or an url that points to a directory" | ||
[f] | ||
(.isDirectory (io/as-file f))) | ||
(if (url? f) | ||
(and (= (.getProtocol ^java.net.URL f) "file") | ||
(.isDirectory (io/as-file f))) | ||
(.isDirectory (io/as-file f)))) | ||
|
||
(defn file-ext? | ||
"Whether the argument's path ends in one of the specified case-insensitive | ||
file extensions" | ||
[f & exts] | ||
(let [file (io/as-file f)] | ||
(when-let [file (if (url? f) | ||
(when (= (.getProtocol ^java.net.URL f) "file") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you can combine this condition with the previous using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still something to do here? |
||
(io/as-file f)) | ||
(io/as-file f))] | ||
(some (fn [ext] | ||
(.endsWith (.. file getName toLowerCase) ext)) | ||
exts))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you can pull this
and
higher.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean like this ?
Then it would not check nonURLs correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of something like:
(and (url? f) (= (.getProtocol ^java.net.URL f) "file")) ...
With a more complex conditional you can even get rid of the duplicated .isDirectory check, but this will probably make the code hard to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but i still do not understand.
You mean like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I just realized where your confusion was coming from. If we structure the condition in this manner, the else branch won't be correct. I should stop reviewing code while doing something else. :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem