forked from technomancy/leiningen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean.clj
More file actions
38 lines (32 loc) · 1.23 KB
/
Copy pathclean.clj
File metadata and controls
38 lines (32 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(ns leiningen.clean
"Remove all files from project's target-path."
(:require [clojure.java.io :as io]
[leiningen.core.eval :as eval]
[leiningen.core.utils :as utils]))
(defn real-directory?
"Returns true if this file is a real directory, false if it is a symlink or a
normal file."
[f]
(if (= :windows (eval/get-os))
(.isDirectory f)
(and (.isDirectory f)
(not (utils/symlink? f)))))
(defn delete-file-recursively
"Delete file f. If it's a directory, recursively delete all its contents.
Raise an exception if any deletion fails unless silently is true."
[f & [silently]]
(let [f (io/file f)]
(when (real-directory? f)
(doseq [child (.listFiles f)]
(delete-file-recursively child silently)))
(.setWritable f true)
(io/delete-file f silently)))
(defn clean
"Remove all files from paths in project's clean-targets."
[project]
(doseq [target-key (:clean-targets project)]
(when-let [target (cond (vector? target-key) (get-in project target-key)
(keyword? target-key) (target-key project)
(string? target-key) target-key)]
(doseq [f (flatten [target])]
(delete-file-recursively f :silently)))))