Skip to content

--include with globs not working correctly for nested files #429

Closed
@ckipp01

Description

@ckipp01

While working on scala/docs.scala-lang#1838 I sort of hit a wall with trying to figure out the correct glob syntax to correctly target all nested markdown files. For example, give the following test case:

  checkCli(
    "nested includes",
    """|readme.md
       |# Readme
       |/docs/first.md
       |# First
       |/docs/nested/second.md
       |# Second
       |/docs/nested/another/third.md
       |# Third
       |""".stripMargin,
    """|readme.md
       |# Readme
       |/docs/first.md
       |# First
       |/docs/nested/second.md
       |# Second
       |/docs/nested/another/third.md
       |# Third
       |""".stripMargin,
    extraArgs = Array(
      "--include",
      "glob:**.md"
    )

However, this fails and doesn't actually process any of the markdown files. If I change the glob:**.md to just **.md assuming that maybe the glob: is not needed, then it only finds First and Second, missing Third and `Readme.

Throwing these same paths in a worksheet result in the following:

import java.nio.file.Paths
import java.nio.file.FileSystems
import java.time.Instant

val fs = FileSystems.getDefault() // : java.nio.file.FileSystem = sun.nio.fs.MacOSXFileSystem@2e4fe51b
val pm = fs.getPathMatcher("glob:**.md") // : java.nio.file.PathMatcher = sun.nio.fs.UnixFileSystem$3@2f28e724

val path1 = Paths.get("readme.md") // : java.nio.file.Path = readme.md
val path2 = Paths.get("/docs/one.md") // : java.nio.file.Path = /docs/one.md
val path3 = Paths.get("/docs/nested/two.md") // : java.nio.file.Path = docs/nested/two.md
val path4 = Paths.get("/docs/nested/another/three.md") // : java.nio.file.Path = docs/nested/another/three.md
 
pm.matches(path1) // : Boolean true
pm.matches(path2) // : Boolean true
pm.matches(path3) // : Boolean true
pm.matches(path4) // : Boolean true

So I would expect one of either glob:**.md or **.md here to cause this test to pass. My initial poking around shows odd results in this call here:

(include.isEmpty || include.exists(_.matches(path.toNIO))) &&

When I'd expect include.exists(_.matches(path.toNIO))) to be returning true as with the matches calls above, but it's not behaving the same at all. I'm curious if anything jumps out to you or if you have any ideas what may be going on here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions