Skip to content

Commit 4d917dc

Browse files
committed
add listLeafDirStatuses and listLeafDirStatusesback to SparkHadoopUtil.scala
1 parent 6e63856 commit 4d917dc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

core/src/main/scala/org/apache/spark/deploy/SparkHadoopUtil.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,27 @@ private[spark] class SparkHadoopUtil extends Logging {
225225
if (baseStatus.isDirectory) recurse(baseStatus) else Seq(baseStatus)
226226
}
227227

228+
/**
229+
* [LYFT-INTERNAL] Removed from OSS Spark: https://github.com/apache/spark/pull/40942/
230+
*/
231+
def listLeafDirStatuses(fs: FileSystem, basePath: Path): Seq[FileStatus] = {
232+
listLeafDirStatuses(fs, fs.getFileStatus(basePath))
233+
}
234+
235+
/**
236+
* [LYFT-INTERNAL] Removed from OSS Spark: https://github.com/apache/spark/pull/40942/
237+
*/
238+
def listLeafDirStatuses(fs: FileSystem, baseStatus: FileStatus): Seq[FileStatus] = {
239+
def recurse(status: FileStatus): Seq[FileStatus] = {
240+
val (directories, files) = fs.listStatus(status.getPath).partition(_.isDirectory)
241+
val leaves = if (directories.isEmpty) Seq(status) else Seq.empty[FileStatus]
242+
leaves ++ directories.flatMap(dir => listLeafDirStatuses(fs, dir))
243+
}
244+
245+
assert(baseStatus.isDirectory)
246+
recurse(baseStatus)
247+
}
248+
228249
def isGlobPath(pattern: Path): Boolean = {
229250
pattern.toString.exists("{}[]*?\\".toSet.contains)
230251
}

0 commit comments

Comments
 (0)