fixed remove path for paths deeper than one eleme

This commit is contained in:
jem 2020-01-30 11:46:20 +01:00
parent e7c853cd0f
commit 4d638f84d9

View file

@ -86,6 +86,7 @@
path path
(Paths/get (user-dir) (into-array String path-elements))))) (Paths/get (user-dir) (into-array String path-elements)))))
; TODO replace this fn ?
(defn path (defn path
"Creates path from given parts, ignore empty elements" "Creates path from given parts, ignore empty elements"
[& path-parts] [& path-parts]
@ -165,18 +166,23 @@
(when (some? resource) (when (some? resource)
(:java-path resource)))) (:java-path resource))))
(defn remove-first-path-item (defn filter-and-remove-for-dir
[seq-of-paths] [path-to-filter-for
(let [fun (fn [str-arg] (st/join "/" (rest (st/split str-arg #"/"))))] elements-list]
(map fun seq-of-paths))) (let [norm-path-to-filter-for (str path-to-filter-for "/")]
(map
#(subs % (count norm-path-to-filter-for))
(filter
(fn [element] (and (st/starts-with? element norm-path-to-filter-for)
(not (= element norm-path-to-filter-for))))
elements-list))))
(s/defn (s/defn
list-entries-for-dir ;:- [VirtualPath] list-entries-for-dir ;:- [VirtualPath]
[resource :- Resource] [resource :- Resource]
(if (= :java-classpath-jar (:source-type resource)) (if (= :java-classpath-jar (:source-type resource))
(remove-first-path-item (filter (filter-and-remove-for-dir
(fn [je] (and (st/starts-with? je (:virtual-path resource)) (:virtual-path resource)
(not (= je (str (:virtual-path resource) "/")))))
(map #(.getName ^JarEntry %) (map #(.getName ^JarEntry %)
(enumeration-seq (enumeration-seq
(.entries (.entries
@ -185,11 +191,10 @@
(Paths/get (Paths/get
(URI. (URI.
(.getSchemeSpecificPart (.getSchemeSpecificPart
(filesystem-uri (:java-uri resource)))))))))))) (filesystem-uri (:java-uri resource)))))))))))
; Bsp-Code: https://github.com/clojure/java.classpath/blob/c10fc96a8ff98db4eb925a13ef0f5135ad8dacc6/src/main/clojure/clojure/java/classpath.clj#L50
(.list (.toFile (:java-path resource))))) (.list (.toFile (:java-path resource)))))
(defn get-resources-recursive ;:- [Resource] (defn get-resources-recursive ;:- [Resource]
[fs-prefix ;:- Prefix [fs-prefix ;:- Prefix
base-path ;:- VirtualPath base-path ;:- VirtualPath
paths ;:- [VirtualPath] paths ;:- [VirtualPath]
@ -222,7 +227,7 @@
result)))) result))))
result))) result)))
(defn get-resource-paths-recursive ;:- [VirtualPath] (defn get-resource-paths-recursive ;:- [VirtualPath]
[fs-prefix ;:- Prefix [fs-prefix ;:- Prefix
base-path ;:- VirtualPath base-path ;:- VirtualPath
paths ;:- [VirtualPath] paths ;:- [VirtualPath]
@ -236,7 +241,7 @@
:from-fs from-fs))) :from-fs from-fs)))
; TODO: Add files to keep ; TODO: Add files to keep
(s/defn delete-resource-recursive! (s/defn delete-resource-recursive!
[virtual-path :- s/Str] [virtual-path :- s/Str]
(let [resource-paths (let [resource-paths
(reverse (get-resource-paths-recursive (reverse (get-resource-paths-recursive
@ -249,7 +254,7 @@
))) )))
; TODO: add ignore patterns filtering ; TODO: add ignore patterns filtering
(defn copy-resources! (defn copy-resources!
[fs-prefix ;:- Prefix [fs-prefix ;:- Prefix
base-path ;:- VirtualPath base-path ;:- VirtualPath
source-paths ;:- [VirtualPath] source-paths ;:- [VirtualPath]
@ -273,7 +278,7 @@
(Files/copy source-file target-file (into-array StandardCopyOption [StandardCopyOption/COPY_ATTRIBUTES StandardCopyOption/REPLACE_EXISTING])) (Files/copy source-file target-file (into-array StandardCopyOption [StandardCopyOption/COPY_ATTRIBUTES StandardCopyOption/REPLACE_EXISTING]))
)))))) ))))))
(defn distinct-resources-by-path (defn distinct-resources-by-path
[resources] [resources]
(loop [paths (set (map :virtual-path resources)) (loop [paths (set (map :virtual-path resources))
resources resources resources resources