This commit is contained in:
jem 2019-12-13 16:53:24 +01:00
parent 5ad40301bf
commit bb53615ed5
2 changed files with 46 additions and 30 deletions

View file

@ -68,16 +68,23 @@
paths :- [s/Str]] paths :- [s/Str]]
(loop [paths paths (loop [paths paths
result []] result []]
(when (not (empty? paths)) (if (not (empty? paths))
(let [path-to-work-with (first paths) (do
path-content (.list (io/file (file-from-cp-or-filesystem (let [path-to-work-with (first paths)
fs-prefix file-to-work-with (io/file (file-from-cp-or-filesystem
(str base-path "/" path-to-work-with)))) fs-prefix
file-list (filter #(.isFile (io/file %)) path-content) (str base-path "/" path-to-work-with)))
dir-list (filter #(not (.isFile %)) path-content)] result (into result [path-to-work-with])]
(println path-content) (cond
;(println file-list) (nil? file-to-work-with) []
(into result file-list))))) (.isFile file-to-work-with) (recur (drop 1 paths) result)
:else
(recur (into (drop 1 paths)
(map #(str path-to-work-with "/" %)
(.list file-to-work-with)))
result)
)))
result)))
(defn copy-file (defn copy-file
[source-file [source-file
@ -87,10 +94,10 @@
(defn do-copy (defn do-copy
[source-dir target-dir ignore-patterns] [source-dir target-dir ignore-patterns]
(loop [source-list (.list source-dir) (loop [source-list (.list source-dir)
file-path-prefix [""]] file-path-prefix [""]]
(let [f (first source-list) (let [f (first source-list)
second? (not (nil? (second source-list))) second? (not (nil? (second source-list)))
target-file (io/file target-dir (str (first file-path-prefix) f)) target-file (io/file target-dir (str (first file-path-prefix) f))
source-file (io/file source-dir (str (first file-path-prefix) f))] source-file (io/file source-dir (str (first file-path-prefix) f))]
(if (.isFile source-file) (if (.isFile source-file)
@ -105,8 +112,8 @@
(defn copy-resources (defn copy-resources
[fs-prefix source-path target-path ignore-patterns] [fs-prefix source-path target-path ignore-patterns]
(let [source-file (file-from-cp-or-filesystem fs-prefix source-path) (let [source-file (file-from-cp-or-filesystem fs-prefix source-path)
target-file (io/file target-path source-path) target-file (io/file target-path source-path)
is-source-dir? (.isDirectory source-file)] is-source-dir? (.isDirectory source-file)]
(if (nil? source-file) (if (nil? source-file)
(throw (IllegalArgumentException. (str "resource " source-path " not found"))) (throw (IllegalArgumentException. (str "resource " source-path " not found")))

View file

@ -26,22 +26,31 @@
(.isDirectory (io/file path)))) (.isDirectory (io/file path))))
(deftest test-get-file-paths-recursive (deftest test-get-file-paths-recursive
(is (= (is (=
[]
(sut/get-file-paths-recursive "" "templates/themes/bootstrap4-test" ["not-existing"])))
(is (=
["js/dummy.js"] ["js/dummy.js"]
(sut/get-file-paths-recursive "" "templates/themes/bootstrap4-test" ["js/dummy.js"])) (sut/get-file-paths-recursive "" "templates/themes/bootstrap4-test" ["js/dummy.js"])))
(is (= (is (=
["/css/dummy.css" ["js/subdir"
"css" "js/subdir/test.js"
"/html/404.html" "js/subdir/subdummy.js"]
"/html/403.html" (sut/get-file-paths-recursive "" "templates/themes/bootstrap4-test" ["js/subdir"])))
"/html" (is (=
"html" ["."
"js/subdir/subdummy.js" "./css"
"js/subdir/test.js" "./css/dummy.css"
"js/subdir" "./js"
"js/dummy.js" "./js/subdir"
"js"] "./js/subdir/test.js"
(sut/get-file-paths-recursive "" "templates/themes/bootstrap4-test" [""]))))) "./js/subdir/subdummy.js"
"./js/dummy.js"
"./html"
"./html/403.html"
"./html/404.html"]
(sut/get-file-paths-recursive "" "templates/themes/bootstrap4-test" ["."])))
)
; (deftest test-delete-file-recursive ; (deftest test-delete-file-recursive
; (is ; (is