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")))))