Skip to content

Commit

Permalink
Merge pull request #2489 from tgodzik/debug-failing
Browse files Browse the repository at this point in the history
 bugfix: Use last modified time instead of creation time for detecting orphaned directories
  • Loading branch information
tgodzik authored Nov 6, 2024
2 parents df40056 + 84ee587 commit e613709
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion frontend/src/main/scala/bloop/data/ClientInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ object ClientInfo {
val dirName = clientDir.underlying.getFileName().toString
val attrs =
Files.readAttributes(clientDir.underlying, classOf[BasicFileAttributes])
val isOldDir = attrs.creationTime.toInstant.isBefore(deletionThresholdInstant)
val isOldDir = attrs.lastModifiedTime.toInstant.isBefore(deletionThresholdInstant)
val isAllowed = CliClientInfo.isStableDirName(dirName) ||
connectedBspClientIds.exists(clientId => dirName.endsWith(s"-$clientId"))

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/main/scala/bloop/engine/State.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object State {
val opts = CommonOptions.default
val cwd = opts.workingPath
val clientInfo = ClientInfo.CliClientInfo(useStableCliDirs = true, () => true)
val results = ResultsCache.load(build, cwd, cleanOrphanedInternalDirs = false, logger)
val results = ResultsCache.load(build, cwd, cleanOrphanedInternalDirs = true, logger)
State(
build,
results,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ object ResultsCache {
fileName.startsWith(genericClassesName) &&
path != analysisClassesDir.underlying
if (isOrphan) {
logger.debug(
s"Discovered orphan directory $path"
)(DebugFilter.All)
orphanInternalDirs.+=(path)
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/test/scala/bloop/bsp/BspCompileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class BspCompileSpec(
}
}

testMac(
testNonWindows(
"create orphan client classes directory and make sure loading a BSP session cleans it up"
) {
TestUtil.withinWorkspace { workspace =>
Expand Down
16 changes: 16 additions & 0 deletions shared/src/main/scala/bloop/logging/FlushingOutputStream.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package bloop.logging

import java.io.ByteArrayOutputStream

class FlushingOutputStream(write: String => Unit) extends ByteArrayOutputStream {

override def flush(): Unit = {
write(this.toByteArray().toString())
}

override def close(): Unit = {
flush();
super.close();
}

}
5 changes: 4 additions & 1 deletion shared/src/main/scala/bloop/logging/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ abstract class Logger extends xsbti.Logger with BaseSbtLogger {

// Duplicate the standard output so that we get printlns from the compiler
protected def redirectOutputToLogs(out: PrintStream) = {
System.setOut(new TeeOutputStream(out))
val baos = new FlushingOutputStream(info)
val tee = new TeeOutputStream(out)
tee.addListener(baos)
System.setOut(tee)
}

/** The name of the logger */
Expand Down

0 comments on commit e613709

Please sign in to comment.