Skip to content

Commit

Permalink
refactor: Refactor util.dep/normalize-path to use Path/normalize #125
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Dec 18, 2021
1 parent aa2744d commit 7340d66
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions src/antq/util/dep.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,15 @@

(defn normalize-path
[^String path]
(let [sep (System/getProperty "file.separator")
file (io/file path)]
(let [file (io/file path)]
(try
(if (= (.getAbsoluteFile file)
(.getCanonicalPath file))
path
(loop [[v :as elements] (seq (.split path sep))
accm []]
(if-not v
(str/join sep accm)
(recur (rest elements)
(condp = v
"." (cond
(seq accm) accm
(seq (rest elements)) accm
:else (conj accm v))

".." (if (seq accm)
(vec (butlast accm))
(conj accm v))
(conj accm v))))))
(let [path' (-> file
(.toPath)
(.normalize)
(str))]
(if (and (not (str/blank? path))
(str/blank? path'))
"."
path'))
(catch Exception _
(.getCanonicalPath file)))))

0 comments on commit 7340d66

Please sign in to comment.