Skip to content

Commit 65d7d1b

Browse files
committed
feat: introduce stencil.fs/unroll
1 parent b599fa0 commit 65d7d1b

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/stencil/fs.clj

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@
1515

1616
(defn parent-file ^File [^File f]
1717
(.getParentFile f))
18+
19+
;; remove /../ parts
20+
(defn unroll [^File f] (-> f .toPath .normalize .toFile))

src/stencil/model.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
path-parent (some-> m ::path file fs/parent-file)]
130130
relation (vals (:parsed (:relations m)))
131131
:when (not= "External" (::mode relation))
132-
:let [path (fs/unix-path (.toFile (.normalize (.toPath (file path-parent (::target relation))))))]
132+
:let [path (fs/unix-path (fs/unroll (file path-parent (::target relation))))]
133133
:when (or (:writer relation) (not (contains? result path)))
134134
:let [src (or (:source-file relation) (file @src-parent (::target relation)))]]
135135
[path (or (:writer relation)

test/stencil/fs_test.clj

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@
2525
(is (true? (fs/exists? (file "/tmp"))))
2626
(is (true? (fs/exists? (file "src"))))
2727
(is (false? (fs/exists? (file "/does/not-exist"))))
28-
(is (false? (fs/exists? (file "does/not-exist")))))
28+
(is (false? (fs/exists? (file "does/not-exist")))))
29+
30+
(deftest test-unroll
31+
(is (= (file "a/b/c/d") (fs/unroll (file "a/b/x/../c/d")))))

0 commit comments

Comments
 (0)