Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we don't hash directory when using globs #1328

Merged
merged 1 commit into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/main/scala/bloop/io/SourceHasher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ object SourceHasher {
def visitFile(file: Path, attributes: BasicFileAttributes): FileVisitResult = {
if (isCancelled.get) FileVisitResult.TERMINATE
else {
if (!matches(file)) ()
// `visitFile` can be called on a directory if we reach the max depth.
if (attributes.isDirectory || !matches(file)) ()
else observer.onNext(file)
FileVisitResult.CONTINUE
}
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/test/scala/bloop/io/SourcesGlobsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ object SourcesGlobsSpec extends bloop.testing.BaseSuite {
filenames: List[String],
includeGlobs: List[String],
excludeGlobs: List[String],
expectedFilenames: String
expectedFilenames: String,
walkDepth: Option[Int] = None
)(implicit filename: sourcecode.File, line: sourcecode.Line): Unit =
test(name) {
TestUtil.withinWorkspace { workspace =>
Expand All @@ -37,7 +38,7 @@ object SourcesGlobsSpec extends bloop.testing.BaseSuite {
val sourcesGlobs = SourcesGlobs.fromStrings(
name,
globDirectory,
None,
walkDepth,
if (includeGlobs.isEmpty) List("glob:**")
else includeGlobs,
excludeGlobs,
Expand Down Expand Up @@ -158,4 +159,12 @@ object SourcesGlobsSpec extends bloop.testing.BaseSuite {
)
}

checkGlobs(
"file too deep",
List("src/main/scala/pkg/source.scala"),
List("glob:src/main/scala/*"),
Nil,
"",
Some(4)
)
}