Skip to content
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

Transform *.ext patterns to **.ext #443

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Fixed

- Fix beholder watch functionality that would cause a NullPointerException earlier.
- `*.<ext>` will now match files with `.ext` extensions in any directory.

## Changed

Expand Down
13 changes: 12 additions & 1 deletion src/kaocha/watch.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@
(assoc tracker ::tracker-error e)
(throw e)))))

(defn- fix-pattern
"beholder, the file change watcher, will always produce fully qualified paths.
A '*.<ext>' pattern will never match anything.
Such a pattern will be prefixed with '*'.
This will cause the pattern to match all files ending in '.<ext>' in any directory."
[pattern]
(assert (string? pattern))
(if (str/starts-with? pattern "*.")
(str "*" pattern)
pattern))

(defn glob?
"Does path match any of the glob patterns.

Expand All @@ -96,7 +107,7 @@
[path patterns]
(assert (instance? Path path))
(let [fs (FileSystems/getDefault)
patterns (map #(.getPathMatcher fs (str "glob:" %)) patterns)]
patterns (map #(.getPathMatcher fs (str "glob:" (fix-pattern %))) patterns)]
(some #(.matches ^PathMatcher % path) patterns)))

(defn convert
Expand Down
Loading