From 2bb7499fd55fa2b4c2687f14e09891cb2fa45265 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sun, 7 Nov 2021 12:05:16 +0100 Subject: [PATCH] [#1055] Segfault when reifying FileVisitor with visitFileFailed --- resources/META-INF/babashka/deps.edn | 5 ++--- src/babashka/impl/reify.clj | 3 ++- test/babashka/reify_test.clj | 32 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/resources/META-INF/babashka/deps.edn b/resources/META-INF/babashka/deps.edn index 3fdd6501..6217666d 100644 --- a/resources/META-INF/babashka/deps.edn +++ b/resources/META-INF/babashka/deps.edn @@ -19,7 +19,7 @@ babashka/babashka.curl {:local/root "babashka.curl"} babashka/fs {:local/root "fs"} borkdude/graal.locking {:mvn/version "0.0.2"}, - org.clojure/core.async {:mvn/version "1.3.618"}, + org.clojure/core.async {:mvn/version "1.4.627"}, org.clojure/tools.cli {:mvn/version "1.0.206"}, org.clojure/data.csv {:mvn/version "1.0.0"}, cheshire/cheshire {:mvn/version "5.10.1"} @@ -39,8 +39,7 @@ rewrite-clj/rewrite-clj {:mvn/version "1.0.699-alpha"} selmer/selmer {:mvn/version "1.12.44"} com.taoensso/timbre {:mvn/version "5.1.2"} - org.clojure/tools.logging {:mvn/version "1.1.0"} - #_#_borkdude/edamame {:local/root "../edamame"}} + org.clojure/tools.logging {:mvn/version "1.1.0"}} :aliases {:babashka/dev {:main-opts ["-m" "babashka.main"]} :profile diff --git a/src/babashka/impl/reify.clj b/src/babashka/impl/reify.clj index 8a3671f3..b5550931 100644 --- a/src/babashka/impl/reify.clj +++ b/src/babashka/impl/reify.clj @@ -67,7 +67,8 @@ java.nio.file.FileVisitor {preVisitDirectory [[this p attrs]] postVisitDirectory [[this p attrs]] - visitFile [[this p attrs]]} + visitFile [[this p attrs]] + visitFileFailed [[this p ex]]} java.io.FileFilter {accept [[this f]]} diff --git a/test/babashka/reify_test.clj b/test/babashka/reify_test.clj index 1e094f5e..72624c65 100644 --- a/test/babashka/reify_test.clj +++ b/test/babashka/reify_test.clj @@ -65,3 +65,35 @@ (toString [_] (str :foo)))) (hash m) "))))) + +(deftest reify-file-visitor-test + (let [prog '(do (ns dude + (:import + [java.io File] + [java.nio.file FileSystems FileVisitor FileVisitResult Files Path]) + (:gen-class)) + + (defn match-paths + "Match glob to paths under root and return a collection of Path objects" + [^File root glob] + (let [root-path (.toPath root) + matcher (.getPathMatcher (FileSystems/getDefault) (str "glob:" glob)) + paths (volatile! []) + visitor (reify FileVisitor + (visitFile [_ path attrs] + (when (.matches matcher (.relativize root-path ^Path path)) + (vswap! paths conj path)) + FileVisitResult/CONTINUE) + (visitFileFailed [_ path ex] + FileVisitResult/CONTINUE) + (preVisitDirectory [_ _ _] FileVisitResult/CONTINUE) + (postVisitDirectory [_ _ _] FileVisitResult/CONTINUE))] + (Files/walkFileTree root-path visitor) + @paths)) + + [(count (match-paths (File. ".") "**")) + ;; visitFileFailed is implemented + (count (match-paths (File. "xxx") "**"))]) + [x y] (bb nil prog)] + (is (pos? x)) + (is (zero? y))))