Skip to content

Commit 48cc648

Browse files
committed
improve deletion
1 parent a69e3e6 commit 48cc648

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

core/src/test/scala/org/apache/spark/deploy/IvyTestUtils.scala

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private[deploy] object IvyTestUtils {
5151
new File(prefix, artifactPath)
5252
}
5353

54+
/** Returns the artifact naming based on standard ivy or maven format. */
5455
private def artifactName(
5556
artifact: MavenCoordinate,
5657
useIvyLayout: Boolean,
@@ -62,6 +63,15 @@ private[deploy] object IvyTestUtils {
6263
}
6364
}
6465

66+
/** Returns the directory for the given groupId based on standard ivy or maven format. */
67+
private def getBaseGroupDirectory(artifact: MavenCoordinate, useIvyLayout: Boolean): String = {
68+
if (!useIvyLayout) {
69+
artifact.groupId.replace(".", File.separator)
70+
} else {
71+
artifact.groupId
72+
}
73+
}
74+
6575
/** Write the contents to a file to the supplied directory. */
6676
private def writeFile(dir: File, fileName: String, contents: String): File = {
6777
val outputFile = new File(dir, fileName)
@@ -302,29 +312,38 @@ private[deploy] object IvyTestUtils {
302312
useIvyLayout: Boolean = false,
303313
withPython: Boolean = false,
304314
ivySettings: IvySettings = new IvySettings)(f: String => Unit): Unit = {
305-
try {
306-
// delete the artifact from the cache as well if it already exists
307-
FileUtils.deleteDirectory(new File(ivySettings.getDefaultCache, artifact.groupId))
308-
}
315+
val deps = dependencies.map(SparkSubmitUtils.extractMavenCoordinates)
316+
purgeLocalIvyCache(artifact, deps, ivySettings)
309317
val repo = createLocalRepositoryForTests(artifact, dependencies, rootDir, useIvyLayout,
310318
withPython)
311319
try {
312320
f(repo.toURI.toString)
313321
} finally {
314322
// Clean up
315323
if (repo.toString.contains(".m2") || repo.toString.contains(".ivy2")) {
316-
FileUtils.deleteDirectory(new File(repo,
317-
artifact.groupId.replace(".", File.separator) + File.separator + artifact.artifactId))
318-
dependencies.map(SparkSubmitUtils.extractMavenCoordinates).foreach { seq =>
319-
seq.foreach { dep =>
320-
FileUtils.deleteDirectory(new File(repo,
321-
dep.artifactId.replace(".", File.separator)))
324+
val groupDir = getBaseGroupDirectory(artifact, useIvyLayout)
325+
FileUtils.deleteDirectory(new File(repo, groupDir + File.separator + artifact.artifactId))
326+
deps.foreach { _.foreach { dep =>
327+
FileUtils.deleteDirectory(new File(repo, getBaseGroupDirectory(dep, useIvyLayout)))
322328
}
323329
}
324330
} else {
325331
FileUtils.deleteDirectory(repo)
326332
}
327-
FileUtils.deleteDirectory(new File(ivySettings.getDefaultCache, artifact.groupId))
333+
purgeLocalIvyCache(artifact, deps, ivySettings)
334+
}
335+
}
336+
337+
/** Deletes the test packages from the ivy cache */
338+
private def purgeLocalIvyCache(
339+
artifact: MavenCoordinate,
340+
dependencies: Option[Seq[MavenCoordinate]],
341+
ivySettings: IvySettings): Unit = {
342+
// delete the artifact from the cache as well if it already exists
343+
FileUtils.deleteDirectory(new File(ivySettings.getDefaultCache, artifact.groupId))
344+
dependencies.foreach { _.foreach { dep =>
345+
FileUtils.deleteDirectory(new File(ivySettings.getDefaultCache, dep.groupId))
346+
}
328347
}
329348
}
330349
}

0 commit comments

Comments
 (0)