From 0329741f9e63439f3267cd93830547ff08c56e44 Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Thu, 21 Sep 2023 15:04:21 +0800 Subject: [PATCH] check isDirectory in home dir filter --- .../scala/org/apache/kyuubi/engine/ProcBuilder.scala | 8 +++++--- .../apache/kyuubi/engine/spark/SparkProcessBuilder.scala | 9 ++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/ProcBuilder.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/ProcBuilder.scala index 1f7326e0091..4a10955005d 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/ProcBuilder.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/ProcBuilder.scala @@ -17,7 +17,7 @@ package org.apache.kyuubi.engine -import java.io.{File, FilenameFilter, IOException} +import java.io.{File, FileFilter, IOException} import java.net.URI import java.nio.charset.StandardCharsets import java.nio.file.{Files, Path, Paths} @@ -296,8 +296,10 @@ trait ProcBuilder { } } - protected lazy val engineHomeDirFilter: FilenameFilter = (_: File, name: String) => - name.contains(s"$shortName-") && !name.contains("-engine") + protected lazy val engineHomeDirFilter: FileFilter = (f: File) => { + val fileName = f.getName + f.isDirectory && fileName.contains(s"$shortName-") && !fileName.contains("-engine") + } /** * Get the home directly that contains binary distributions of engines. diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilder.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilder.scala index ff4ca77d85b..22cc2866475 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilder.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/spark/SparkProcessBuilder.scala @@ -17,7 +17,7 @@ package org.apache.kyuubi.engine.spark -import java.io.{File, FilenameFilter, IOException} +import java.io.{File, FileFilter, IOException} import java.nio.file.Paths import java.util.Locale @@ -27,7 +27,6 @@ import scala.collection.mutable.ArrayBuffer import com.google.common.annotations.VisibleForTesting import org.apache.commons.lang3.StringUtils import org.apache.hadoop.security.UserGroupInformation -import org.apache.hadoop.shaded.org.apache.commons.io.filefilter.RegexFileFilter import org.apache.kyuubi._ import org.apache.kyuubi.config.KyuubiConf @@ -105,7 +104,7 @@ class SparkProcessBuilder( private lazy val sparkCoreScalaVersion: String = { Paths.get(sparkHome, "jars").toFile - .list(new RegexFileFilter("^spark-core_.*\\.jar$")) + .list((_, name) => name.matches("^spark-core_.*\\.jar$")) .map { p => p.substring(p.indexOf("_") + 1, p.lastIndexOf("-")) } .head } @@ -113,13 +112,13 @@ class SparkProcessBuilder( override protected def engineScalaBinaryVersion: String = StringUtils.defaultIfBlank(System.getenv("SPARK_SCALA_VERSION"), sparkCoreScalaVersion) - override protected lazy val engineHomeDirFilter: FilenameFilter = { + override protected lazy val engineHomeDirFilter: FileFilter = (file: File) => { val pattern = if (SemanticVersion(SCALA_COMPILE_VERSION) >= "2.13") { "^spark-\\d+\\.\\d+\\.\\d+-bin-hadoop\\d(\\.\\d+)?+-scala\\d+(\\.\\d+)?$" } else { "^spark-\\d+\\.\\d+\\.\\d+-bin-hadoop\\d+(\\.\\d+)?$" } - new RegexFileFilter(pattern) + file.isDirectory && file.getName.matches(pattern) } override protected lazy val commands: Array[String] = {