Skip to content

Commit 186c793

Browse files
authored
Fix #88: bbin ls with 0-length files doesn't crash (#89)
1 parent 3852708 commit 186c793

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- [Fix #88: NPE when using `bbin ls` in dirs with zero-length files](https://github.com/babashka/bbin/issues/88)
6+
37
## 0.2.3
48

59
- [Fix error in compiled script when installing from Homebrew (again)](https://github.com/babashka/bbin/commit/f0a3096a1e57408af77eed35f86a3d71cccccb07)

src/babashka/bbin/scripts.clj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@
3333
edn/read-string)))
3434

3535
(defn- read-header [filename]
36-
(with-open [input-stream (io/input-stream filename)]
37-
(let [buffer (byte-array (* 1024 5))
38-
n (.read input-stream buffer)]
39-
(when (nat-int? n)
40-
(String. buffer 0 n)))))
36+
(or (with-open [input-stream (io/input-stream filename)]
37+
(let [buffer (byte-array (* 1024 5))
38+
n (.read input-stream buffer)]
39+
(when (nat-int? n)
40+
(String. buffer 0 n))))
41+
""))
4142

4243
(defn load-scripts [dir]
4344
(->> (file-seq dir)
4445
(filter #(.isFile %))
4546
(map (fn [x] [(symbol (str (fs/relativize dir x)))
46-
(parse-script (read-header x))]))
47+
(-> (read-header x) (parse-script ))]))
4748
(filter second)
4849
(into {})))
4950

0 commit comments

Comments
 (0)