Skip to content

Commit 2568e45

Browse files
committed
improvement: Don't fail during copying
This might cause the compiler to never work again until restart. It seems that the reason might be that one of the files is locked, but this is highly difficult to reproduce. Connected to scalacenter#1989
1 parent 500036a commit 2568e45

5 files changed

Lines changed: 24 additions & 8 deletions

File tree

backend/src/main/scala/bloop/BloopClassFileManager.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ final class BloopClassFileManager(
221221
newClassesDir,
222222
clientExternalClassesDir.underlying,
223223
inputs.ioScheduler,
224-
enableCancellation = false
224+
enableCancellation = false,
225+
inputs.logger
225226
)
226227
.map { walked =>
227228
readOnlyCopyDenylist.++=(walked.target)
@@ -279,7 +280,8 @@ final class BloopClassFileManager(
279280
Paths.get(readOnlyClassesDirPath),
280281
clientExternalClassesDir.underlying,
281282
inputs.ioScheduler,
282-
enableCancellation = false
283+
enableCancellation = false,
284+
inputs.logger
283285
)
284286
.map(_ => ())
285287
}

backend/src/main/scala/bloop/Compiler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ object Compiler {
434434
readOnlyClassesDir,
435435
clientClassesDir.underlying,
436436
compileInputs.ioScheduler,
437-
enableCancellation = false
437+
enableCancellation = false,
438+
compileInputs.logger
438439
)
439440

440441
lastCopy.map { _ =>

backend/src/main/scala/bloop/io/ParallelOps.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import monix.execution.cancelables.CompositeCancelable
2222
import monix.reactive.Consumer
2323
import monix.reactive.MulticastStrategy
2424
import monix.reactive.Observable
25+
import bloop.logging.Logger
26+
import scala.util.control.NonFatal
2527

2628
object ParallelOps {
2729

@@ -67,7 +69,8 @@ object ParallelOps {
6769
origin: Path,
6870
target: Path,
6971
scheduler: Scheduler,
70-
enableCancellation: Boolean
72+
enableCancellation: Boolean,
73+
logger: Logger
7174
): Task[FileWalk] = Task.defer {
7275
val isCancelled = AtomicBoolean(false)
7376

@@ -152,7 +155,7 @@ object ParallelOps {
152155

153156
val copyFileSequentially = Consumer.foreachTask[((Path, BasicFileAttributes), Path)] {
154157
case ((originFile, originAttrs), targetFile) =>
155-
def copy(replaceExisting: Boolean): Unit = {
158+
def copy(replaceExisting: Boolean): Unit = try {
156159
if (replaceExisting) {
157160
Files.copy(
158161
originFile,
@@ -168,6 +171,12 @@ object ParallelOps {
168171
)
169172
}
170173
()
174+
} catch {
175+
case NonFatal(t) =>
176+
logger.report(
177+
s"Unexpected error when copying $originFile to $targetFile, you might need to restart the build server.",
178+
t
179+
)
171180
}
172181

173182
// It's important that this task is not forked for performance reasons

frontend/src/main/scala/bloop/engine/tasks/CompileTask.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ object CompileTask {
364364
products.readOnlyClassesDir,
365365
products.newClassesDir,
366366
ExecutionContext.ioScheduler,
367-
enableCancellation = false
367+
enableCancellation = false,
368+
logger
368369
)
369370
}
370371

frontend/src/test/scala/bloop/testing/BloopHelpers.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import bloop.util.TestUtil
2828

2929
import monix.execution.CancelableFuture
3030
import monix.execution.Scheduler
31+
import bloop.logging.NoopLogger
3132

3233
trait BloopHelpers {
3334
def loadState(
@@ -87,7 +88,8 @@ trait BloopHelpers {
8788
baseDir,
8889
workspace.underlying,
8990
ExecutionContext.ioScheduler,
90-
enableCancellation = false
91+
enableCancellation = false,
92+
logger
9193
)
9294

9395
val loadFromNewWorkspace = copyToNewWorkspace.flatMap { _ =>
@@ -305,7 +307,8 @@ trait BloopHelpers {
305307
classesDir,
306308
newClassesDir,
307309
ExecutionContext.ioScheduler,
308-
enableCancellation = false
310+
enableCancellation = false,
311+
NoopLogger
309312
)
310313

311314
backupDir.map { _ =>

0 commit comments

Comments
 (0)