Skip to content

Update scan-dirs to no longer throw #3

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

Merged
merged 3 commits into from
Jul 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ jobs:
run: |
dotnet tool install --global Clojure.Main --version 1.12.0-alpha10
dotnet tool install --global Clojure.Cljr --version 0.1.0-alpha5

- name: Run cljr tests
run: cljr -X:test
run: cljr -X:test

14 changes: 5 additions & 9 deletions src/main/clojure/clojure/tools/namespace/dir.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
(mapcat #(find/find-sources-in-dir % platform))
)) ;;; ditto: (map #(.getCanonicalFile ^File %))

(defn- milliseconds-since-epoch [^DateTime time]
(long
(/ (- (.-Ticks time)
(.-Ticks DateTime/UnixEpoch))
TimeSpan/TicksPerMillisecond)))
(defn- modified-since-tracked? [tracker file]
(if-let [time (::time tracker)]
(DateTime/op_LessThan time (.LastWriteTimeUtc ^FileSystemInfo file))
true))

(defn- modified-files [tracker files]
(filter #(< (::time tracker 0) (milliseconds-since-epoch (.-LastWriteTimeUtc ^FileSystemInfo %))) files)) ;;; #(< (::time tracker 0) (.lastModified ^File %))
(filter (partial modified-since-tracked? tracker) files)) ;;; (.lastModified ^File %)

(defn- deleted-files [tracker files]
(set (remove #(file/some-file files %) (::files tracker #{})))) ;;; (set/difference (::files tracker #{}) (set files))
Expand Down Expand Up @@ -138,6 +137,3 @@
(instance? DirectoryInfo x) x
(string? x) (DirectoryInfo. ^String x)
:default (DirectoryInfo. (str x))))



13 changes: 12 additions & 1 deletion src/test/clojure/clojure/tools/namespace/dir_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
[clojure.tools.namespace.dir :as dir])
#_(:import
(java.io File)))

(defmacro is-not-thrown? [& body]
`(try
~@body
(is true "No exception thrown")
(catch Exception e#
(is false (str "Expected no exception, but got: " (.GetType e#) ": " (.-Message e#))))))

(deftest scan-dirs-does-not-throw
(is-not-thrown? (dir/scan-dirs {})))

;;; I don't know what the equivalent test would be for .Net.
#_(defn- make-symbolic-link
"Reflectively calls java.nio.file.Files/createSymbolicLink on two
Expand Down Expand Up @@ -35,4 +46,4 @@
link (File. other-dir "link")]
(make-symbolic-link link dir)
(is (= (::dir/files (dir/scan-dirs {} [dir]))
(::dir/files (dir/scan-dirs {} [link])))))))
(::dir/files (dir/scan-dirs {} [link])))))))