Skip to content

Commit 8d22dbb

Browse files
srowenmarmbrus
authored andcommitted
SPARK-3794 [CORE] Building spark core fails due to inadvertent dependency on Commons IO
Remove references to Commons IO FileUtils and replace with pure Java version, which doesn't need to traverse the whole directory tree first. I think this method could be refined further if it would be alright to rename it and its args and break it down into two methods. I'm starting with a simple recursive rendition. Author: Sean Owen <[email protected]> Closes #2662 from srowen/SPARK-3794 and squashes the following commits: 4cd172f [Sean Owen] Remove references to Commons IO FileUtils and replace with pure Java version, which doesn't need to traverse the whole directory tree first
1 parent 90897ea commit 8d22dbb

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

core/src/main/scala/org/apache/spark/deploy/worker/Worker.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import scala.language.postfixOps
2929

3030
import akka.actor._
3131
import akka.remote.{DisassociatedEvent, RemotingLifecycleEvent}
32-
import org.apache.commons.io.FileUtils
3332

3433
import org.apache.spark.{Logging, SecurityManager, SparkConf, SparkException}
3534
import org.apache.spark.deploy.{ExecutorDescription, ExecutorState}

core/src/main/scala/org/apache/spark/util/Utils.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ import scala.util.control.{ControlThrowable, NonFatal}
3535

3636
import com.google.common.io.Files
3737
import com.google.common.util.concurrent.ThreadFactoryBuilder
38-
import org.apache.commons.io.FileUtils
39-
import org.apache.commons.io.filefilter.TrueFileFilter
4038
import org.apache.commons.lang3.SystemUtils
4139
import org.apache.hadoop.conf.Configuration
4240
import org.apache.log4j.PropertyConfigurator
@@ -710,18 +708,20 @@ private[spark] object Utils extends Logging {
710708
* Determines if a directory contains any files newer than cutoff seconds.
711709
*
712710
* @param dir must be the path to a directory, or IllegalArgumentException is thrown
713-
* @param cutoff measured in seconds. Returns true if there are any files in dir newer than this.
711+
* @param cutoff measured in seconds. Returns true if there are any files or directories in the
712+
* given directory whose last modified time is later than this many seconds ago
714713
*/
715714
def doesDirectoryContainAnyNewFiles(dir: File, cutoff: Long): Boolean = {
716-
val currentTimeMillis = System.currentTimeMillis
717715
if (!dir.isDirectory) {
718-
throw new IllegalArgumentException (dir + " is not a directory!")
719-
} else {
720-
val files = FileUtils.listFilesAndDirs(dir, TrueFileFilter.TRUE, TrueFileFilter.TRUE)
721-
val cutoffTimeInMillis = (currentTimeMillis - (cutoff * 1000))
722-
val newFiles = files.filter { _.lastModified > cutoffTimeInMillis }
723-
newFiles.nonEmpty
716+
throw new IllegalArgumentException("$dir is not a directory!")
724717
}
718+
val filesAndDirs = dir.listFiles()
719+
val cutoffTimeInMillis = System.currentTimeMillis - (cutoff * 1000)
720+
721+
filesAndDirs.exists(_.lastModified() > cutoffTimeInMillis) ||
722+
filesAndDirs.filter(_.isDirectory).exists(
723+
subdir => doesDirectoryContainAnyNewFiles(subdir, cutoff)
724+
)
725725
}
726726

727727
/**

0 commit comments

Comments
 (0)