Skip to content

Commit

Permalink
feat: introduce stencil.fs/unroll
Browse files Browse the repository at this point in the history
  • Loading branch information
erdos committed May 15, 2024
1 parent b599fa0 commit 65d7d1b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/stencil/fs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@

(defn parent-file ^File [^File f]
(.getParentFile f))

;; remove /../ parts
(defn unroll [^File f] (-> f .toPath .normalize .toFile))
2 changes: 1 addition & 1 deletion src/stencil/model.clj
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
path-parent (some-> m ::path file fs/parent-file)]
relation (vals (:parsed (:relations m)))
:when (not= "External" (::mode relation))
:let [path (fs/unix-path (.toFile (.normalize (.toPath (file path-parent (::target relation))))))]
:let [path (fs/unix-path (fs/unroll (file path-parent (::target relation))))]
:when (or (:writer relation) (not (contains? result path)))
:let [src (or (:source-file relation) (file @src-parent (::target relation)))]]
[path (or (:writer relation)
Expand Down
5 changes: 4 additions & 1 deletion test/stencil/fs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@
(is (true? (fs/exists? (file "/tmp"))))
(is (true? (fs/exists? (file "src"))))
(is (false? (fs/exists? (file "/does/not-exist"))))
(is (false? (fs/exists? (file "does/not-exist")))))
(is (false? (fs/exists? (file "does/not-exist")))))

(deftest test-unroll
(is (= (file "a/b/c/d") (fs/unroll (file "a/b/x/../c/d")))))

0 comments on commit 65d7d1b

Please sign in to comment.