fs-functions are working now
This commit is contained in:
parent
2d71596a5e
commit
a9a58b0a25
2 changed files with 24 additions and 10 deletions
|
@ -17,19 +17,25 @@
|
|||
|
||||
; ----------------------- Domain functions ------------------------
|
||||
(def no-link-option (into-array [LinkOption/NOFOLLOW_LINKS]))
|
||||
(def follow-link-option (into-array []))
|
||||
(def follow-link-option (into-array LinkOption []))
|
||||
|
||||
(defn user-dir []
|
||||
(java.lang.System/getProperty "user.dir"))
|
||||
|
||||
(s/defn path
|
||||
(defn absolut-path
|
||||
[& path-elements]
|
||||
(let [path (.normalize
|
||||
(Paths/get (first path-elements)
|
||||
(into-array String (rest path-elements))))]
|
||||
(if (.isAbsolute path)
|
||||
path
|
||||
(Paths/get (user-dir) (into-array String path-elements)))))
|
||||
|
||||
(defn path-if-exists
|
||||
[full-path]
|
||||
(let [path-from-fs (Paths/get (URI. (str "file://" (user-dir) "/" full-path)))]
|
||||
(try
|
||||
(when (Files/exists path-from-fs follow-link-option)
|
||||
path-from-fs)
|
||||
(catch Exception e
|
||||
nil))))
|
||||
(when (Files/exists path-from-fs follow-link-option)
|
||||
path-from-fs)))
|
||||
|
||||
(defn create-resource
|
||||
([virtual-path
|
||||
|
|
|
@ -15,9 +15,17 @@
|
|||
|
||||
(def fs-root "fs_root")
|
||||
|
||||
(deftest test-path
|
||||
(deftest test-absolut-path
|
||||
(is
|
||||
(sut/path (str fs-root "/dummy/dummy_from_fs")))
|
||||
(= (str (sut/user-dir) "/" fs-root "/dummy/dummy_from_fs")
|
||||
(.toString (sut/absolut-path fs-root "/dummy/dummy_from_fs"))))
|
||||
(is
|
||||
(= (str (sut/user-dir) "/" fs-root "/not-existing")
|
||||
(.toString (sut/absolut-path (str fs-root "/not-existing"))))))
|
||||
|
||||
(deftest test-path-if-exists
|
||||
(is
|
||||
(sut/path-if-exists (str fs-root "/dummy/dummy_from_fs")))
|
||||
(is
|
||||
(= nil
|
||||
(sut/path (str fs-root "/not-existing")))))
|
||||
(sut/path-if-exists (str fs-root "/not-existing")))))
|
||||
|
|
Loading…
Reference in a new issue