Skip to content

Commit

Permalink
Ignore empty directory layout in external classes dir
Browse files Browse the repository at this point in the history
Because the proces owning external classes directories might force the
creation of certain empty directories, the process responsible for
copying directories would consider the external client classes directory
was not empty and would not copy class files from the internal classes
directory.

This commit fixes that and ignores empty directories in the external
classes dir, resulting in the copying process working as expected.
  • Loading branch information
jvican committed Jul 21, 2020
1 parent 9c2df17 commit e37e36c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions backend/src/main/scala/bloop/BloopClassFileManager.scala
Expand Up @@ -217,14 +217,19 @@ final class BloopClassFileManager(
clientExternalClassesDir: AbsolutePath,
clientReporter: Reporter,
clientTracer: BraveTracer
) => {
clientTracer.traceTask("populate external classes dir as it's empty") { _ =>
Task {
if (!BloopPaths.isDirectoryEmpty(clientExternalClassesDir)) Task.unit
else {
if (BloopPaths.isDirectoryEmpty(outPaths.internalReadOnlyClassesDir)) {
Task.unit
} else {
) =>
Task.defer {
// Exclude dirs because process controlling external dir might have created empty dir layouts
val externalDirHasFiles =
!BloopPaths.isDirectoryEmpty(clientExternalClassesDir, excludeDirs = true)
val isInternalEmpty =
BloopPaths.isDirectoryEmpty(outPaths.internalReadOnlyClassesDir, excludeDirs = false)

if (externalDirHasFiles) Task.unit
else if (isInternalEmpty) Task.unit
else
clientTracer.traceTask("populate empty classes dir") {
_ =>
// Prepopulate external classes dir even though compilation failed
val config = ParallelOps.CopyConfiguration(1, CopyMode.NoReplace, Set.empty)
ParallelOps
Expand All @@ -236,11 +241,8 @@ final class BloopClassFileManager(
enableCancellation = false
)
.map(_ => ())
}
}
}.flatten
}
}
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions shared/src/main/scala/bloop/io/Paths.scala
Expand Up @@ -171,7 +171,7 @@ object Paths {
()
}

def isDirectoryEmpty(path: AbsolutePath): Boolean = {
def isDirectoryEmpty(path: AbsolutePath, excludeDirs: Boolean): Boolean = {
var isEmpty: Boolean = true
import java.nio.file.NoSuchFileException
try {
Expand All @@ -187,7 +187,7 @@ object Paths {
directory: Path,
attributes: BasicFileAttributes
): FileVisitResult = {
if (path.underlying == directory) FileVisitResult.CONTINUE
if (excludeDirs || path.underlying == directory) FileVisitResult.CONTINUE
else {
isEmpty = false
FileVisitResult.TERMINATE
Expand Down

0 comments on commit e37e36c

Please sign in to comment.