From f68862e7841285a4d1847becc0ea3f9d09edf019 Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 23 Mar 2014 09:19:04 -0400 Subject: [PATCH] extract function to check if file exists this will need to be extended to also check for the existance of files inside of jars --- src/clj_jtwig/core.clj | 2 +- src/clj_jtwig/utils.clj | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/clj_jtwig/core.clj b/src/clj_jtwig/core.clj index 496c043..147095f 100644 --- a/src/clj_jtwig/core.clj +++ b/src/clj_jtwig/core.clj @@ -73,7 +73,7 @@ ; this function really only exists so i can easily change the exception type / message in the future ; since this file-exists check is needed in a few places (defn- err-if-no-file [^File file] - (if-not (.exists file) + (if-not (exists? file) (throw (new FileNotFoundException (str "Template file \"" file "\" not found."))))) (defn- cache-compiled-template! [^File file create-fn] diff --git a/src/clj_jtwig/utils.clj b/src/clj_jtwig/utils.clj index 930e4c7..8fe7e66 100644 --- a/src/clj_jtwig/utils.clj +++ b/src/clj_jtwig/utils.clj @@ -9,6 +9,12 @@ ; the path of a file inside a jar looks something like "jar:file:/path/to/file.jar!/path/inside/jar/to/file" (.contains "jar!"))) +(defn exists? [^File file] + (if (inside-jar? file) + ;; TODO: can't use File.exists() for this + true + (.exists file))) + (defn get-file-last-modified [^File file] (if (inside-jar? file) 0