Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use non-recursive version of file-seq #41

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/compliment/utils.clj
@@ -1,6 +1,6 @@
(ns compliment.utils
"Functions and utilities for source implementations."
(:import java.io.File
(:import java.io.File java.nio.file.Files
[java.util.jar JarFile JarEntry]))

(def ^:dynamic *extra-metadata*
Expand Down Expand Up @@ -77,6 +77,21 @@
;; This is where Boot keeps references to dependencies.
"fake.class.path"])))

(defn- symlink?
[f]
(. Files (isSymbolicLink (.toPath f))))

(defn- file-seq-nonr
"A tree seq on java.io.Files, doesn't resolve symlinked directories to avoid
infinite sequence resulting from recursive symlinked directories."
{:added "1.0"
:static true}
[dir]
(tree-seq
(fn [^java.io.File f] (and (. f (isDirectory)) (not (symlink? f))))
(fn [^java.io.File d] (seq (. d (listFiles))))
dir))

(defn- list-files
"Given a path (either a jar file, directory with classes or directory with
paths) returns all files under that path."
Expand All @@ -98,7 +113,7 @@
(= path "") ()

:else
(for [^File file (file-seq (File. path))
(for [^File file (file-seq-nonr (File. path))
:when (not (.isDirectory file))]
(.replace ^String (.getPath file) path ""))))

Expand Down