From 65d7d1b0e231ac880dd8fa56d8e90d6b4df98ebc Mon Sep 17 00:00:00 2001 From: janos erdos Date: Wed, 15 May 2024 23:25:59 +0200 Subject: [PATCH] feat: introduce stencil.fs/unroll --- src/stencil/fs.clj | 3 +++ src/stencil/model.clj | 2 +- test/stencil/fs_test.clj | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/stencil/fs.clj b/src/stencil/fs.clj index 7503d97d..68e9fc29 100644 --- a/src/stencil/fs.clj +++ b/src/stencil/fs.clj @@ -15,3 +15,6 @@ (defn parent-file ^File [^File f] (.getParentFile f)) + +;; remove /../ parts +(defn unroll [^File f] (-> f .toPath .normalize .toFile)) diff --git a/src/stencil/model.clj b/src/stencil/model.clj index 9f213a6a..5878d6b8 100644 --- a/src/stencil/model.clj +++ b/src/stencil/model.clj @@ -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) diff --git a/test/stencil/fs_test.clj b/test/stencil/fs_test.clj index 26ea9dfa..48b25ce5 100644 --- a/test/stencil/fs_test.clj +++ b/test/stencil/fs_test.clj @@ -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"))))) \ No newline at end of file + (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")))))