From 635b6342f5b3d536ced63b6fe2cfcef0120253c8 Mon Sep 17 00:00:00 2001
From: "Paolo G. Giarrusso"
Date: Sat, 11 Aug 2018 01:01:29 +0200
Subject: [PATCH 1/2] Fix #4929: allow reusing TastyFileManager
Recreate `tempDir` if we're reused after `complete` was called and deleted the
existing `tempDir`.
The output in #4929 was produced by this commit.
---
.../dotty/tools/sbtplugin/TastyFileManager.scala | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/sbt-dotty/src/dotty/tools/sbtplugin/TastyFileManager.scala b/sbt-dotty/src/dotty/tools/sbtplugin/TastyFileManager.scala
index b51465480fc3..cd73de8e9351 100644
--- a/sbt-dotty/src/dotty/tools/sbtplugin/TastyFileManager.scala
+++ b/sbt-dotty/src/dotty/tools/sbtplugin/TastyFileManager.scala
@@ -20,7 +20,14 @@ import scala.collection.mutable
* temporary directory as class files.
*/
final class TastyFileManager extends ClassFileManager {
- private[this] val tempDir = Files.createTempDirectory("backup").toFile
+ private[this] var _tempDir: File = null
+ private[this] def tempDir = {
+ if (_tempDir == null) {
+ _tempDir = Files.createTempDirectory("backup").toFile
+ println(s"ClassFileManager.tempDir: creating ${_tempDir} in $this")
+ }
+ _tempDir
+ }
private[this] val generatedTastyFiles = new mutable.HashSet[File]
private[this] val movedTastyFiles = new mutable.HashMap[File, File]
@@ -42,7 +49,11 @@ final class TastyFileManager extends ClassFileManager {
IO.deleteFilesEmptyDirs(generatedTastyFiles)
for ((orig, tmp) <- movedTastyFiles) IO.move(tmp, orig)
}
- IO.delete(tempDir)
+ if (_tempDir != null) {
+ println(s"ClassFileManager.complete($success): deleting $tempDir from $this")
+ IO.delete(tempDir)
+ _tempDir = null
+ }
}
private def tastyFiles(classes: Array[File]): Array[File] = {
@@ -56,6 +67,7 @@ final class TastyFileManager extends ClassFileManager {
}
private def move(c: File): File = {
+ println(s"ClassFileManager.delete: maybe using $tempDir in $this")
val target = File.createTempFile("sbt", ".tasty", tempDir)
IO.move(c, target)
target
From 0d4dc18b2ecafe34fc0d6f30b6122e99e9502167 Mon Sep 17 00:00:00 2001
From: "Paolo G. Giarrusso"
Date: Sat, 11 Aug 2018 01:08:15 +0200
Subject: [PATCH 2/2] Delete println instrumentation
That was only for history, not to be left in the actual plugin.
---
sbt-dotty/src/dotty/tools/sbtplugin/TastyFileManager.scala | 3 ---
1 file changed, 3 deletions(-)
diff --git a/sbt-dotty/src/dotty/tools/sbtplugin/TastyFileManager.scala b/sbt-dotty/src/dotty/tools/sbtplugin/TastyFileManager.scala
index cd73de8e9351..38d4d029f50d 100644
--- a/sbt-dotty/src/dotty/tools/sbtplugin/TastyFileManager.scala
+++ b/sbt-dotty/src/dotty/tools/sbtplugin/TastyFileManager.scala
@@ -24,7 +24,6 @@ final class TastyFileManager extends ClassFileManager {
private[this] def tempDir = {
if (_tempDir == null) {
_tempDir = Files.createTempDirectory("backup").toFile
- println(s"ClassFileManager.tempDir: creating ${_tempDir} in $this")
}
_tempDir
}
@@ -50,7 +49,6 @@ final class TastyFileManager extends ClassFileManager {
for ((orig, tmp) <- movedTastyFiles) IO.move(tmp, orig)
}
if (_tempDir != null) {
- println(s"ClassFileManager.complete($success): deleting $tempDir from $this")
IO.delete(tempDir)
_tempDir = null
}
@@ -67,7 +65,6 @@ final class TastyFileManager extends ClassFileManager {
}
private def move(c: File): File = {
- println(s"ClassFileManager.delete: maybe using $tempDir in $this")
val target = File.createTempFile("sbt", ".tasty", tempDir)
IO.move(c, target)
target