From f05cbf00b242a234d6dc2c689713d4c66387aaf3 Mon Sep 17 00:00:00 2001 From: Simon Olofsson Date: Mon, 27 Jun 2011 16:45:22 +0200 Subject: [PATCH] Recover when gitRetrieve(.) fails. When gitRetrieve(.) fails (e.g. because no git is installed) an exception is thrown but the created directory isn't removed. This commit removes the directory when an exception occurs, so that the user can retry. --- main/Build.scala | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main/Build.scala b/main/Build.scala index 64849676e..6e8d1150e 100644 --- a/main/Build.scala +++ b/main/Build.scala @@ -56,9 +56,14 @@ object RetrieveUnit def gitRetrieve(base: URI, tempDir: File): Unit = if(!tempDir.exists) { - IO.createDirectory(tempDir) - gitClone(dropFragment(base), tempDir) - Option(base.getFragment) foreach { branch => gitCheckout(tempDir, branch) } + try { + IO.createDirectory(tempDir) + gitClone(dropFragment(base), tempDir) + Option(base.getFragment) foreach { branch => gitCheckout(tempDir, branch) } + } catch { + case e => IO.delete(tempDir) + throw e + } } def dropFragment(base: URI): URI = if(base.getFragment eq null) base else new URI(base.getScheme, base.getSchemeSpecificPart, null) def gitClone(base: URI, tempDir: File): Unit = @@ -246,4 +251,4 @@ object BuildPaths final val ConfigDirectoryName = ".sbt" def crossPath(base: File, instance: ScalaInstance): File = base / ("scala_" + instance.version) -} \ No newline at end of file +}