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