From b63ad0621771f49796b13de4c643df45b19e2bf7 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sun, 8 Sep 2024 19:35:25 +0200 Subject: [PATCH] gen-script --- CHANGELOG.md | 2 +- bbin | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40209b5..6dd3066 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/bbin b/bbin index c0bd16a..92b0318 100755 --- a/bbin +++ b/bbin @@ -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) @@ -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 @@ -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 {})))