Skip to content

Commit

Permalink
gen-script
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Sep 8, 2024
1 parent 186c793 commit b63ad06
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Unreleased
## 0.2.4

- [Fix #88: NPE when using `bbin ls` in dirs with zero-length files](https://github.com/babashka/bbin/issues/88)

Expand Down
27 changes: 17 additions & 10 deletions bbin
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ WARNING: (We won't make any changes without asking you first.)
(or (some #(deps-type-match? cli-opts %) deps-types)
{:procurer :unknown-procurer}))

(defn directory? [x]
(fs/directory? (str/replace x #"^file://" "")))

(defn regular-file? [x]
(fs/regular-file? (str/replace x #"^file://" "")))

(defn- match-artifact [cli-opts procurer]
(cond
(or (#{:maven} procurer)
Expand All @@ -371,14 +377,14 @@ WARNING: (We won't make any changes without asking you first.)

(or (#{:git} procurer)
(and (#{:local} procurer)
(or (and (:script/lib cli-opts) (fs/directory? (:script/lib cli-opts)))
(and (:local/root cli-opts) (fs/directory? (:local/root cli-opts)))))
(or (and (:script/lib cli-opts)
(directory? (:script/lib cli-opts)))
(and (:local/root cli-opts) (directory? (:local/root cli-opts)))))
(and (#{:http} procurer) (re-seq #"\.git$" (:script/lib cli-opts))))
:dir

(or (and (#{:local} procurer) (and (:script/lib cli-opts)
(or (fs/regular-file? (:script/lib cli-opts))
(fs/regular-file? (str/replace (:script/lib cli-opts) #"^file://" "")))))
(regular-file? (:script/lib cli-opts))))
(and (#{:http} procurer) (re-seq #"\.(cljc?|bb)$" (:script/lib cli-opts))))
:file

Expand Down Expand Up @@ -1499,17 +1505,18 @@ WARNING: (We won't make any changes without asking you first.)
edn/read-string)))

(defn- read-header [filename]
(with-open [input-stream (io/input-stream filename)]
(let [buffer (byte-array (* 1024 5))
n (.read input-stream buffer)]
(when (nat-int? n)
(String. buffer 0 n)))))
(or (with-open [input-stream (io/input-stream filename)]
(let [buffer (byte-array (* 1024 5))
n (.read input-stream buffer)]
(when (nat-int? n)
(String. buffer 0 n))))
""))

(defn load-scripts [dir]
(->> (file-seq dir)
(filter #(.isFile %))
(map (fn [x] [(symbol (str (fs/relativize dir x)))
(parse-script (read-header x))]))
(-> (read-header x) (parse-script ))]))
(filter second)
(into {})))

Expand Down

0 comments on commit b63ad06

Please sign in to comment.