Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8341

GDK: eachDirRecurse and eachFileRecurse are NOT depth-first

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.11
    • 2.4.13
    • groovy-jdk
    • None
    • Windows Linux

    Description

      The documentation for those two methods states: "Sub-directories are recursively searched in a depth-first fashion." But the result is NOT depth-first, as the following example shows:

      Given a directory tree of

      /tmp
      |-/foo
      | |-/bar
      |   |-/foo
      |   |-/bar
      |   |-/baz
      |-/baz

      the following simple code

      #!/usr/bin/groovy
      
      File rootDir = new File(new URI('file:/tmp/foo'))
      rootDir.eachDirRecurse {
        println(it)
      }

      gives this result

      /tmp/foo/bar
      /tmp/foo/bar/baz
      /tmp/foo/bar/foo
      /tmp/foo/bar/bar
      /tmp/foo/baz

      while

      % find /tmp/foo -depth -type d

      correctly gives

      /tmp/foo/bar/baz
      /tmp/foo/bar/foo
      /tmp/foo/bar/bar
      /tmp/foo/bar
      /tmp/foo/baz
      /tmp/foo

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              dheinric Dirk Heinrichs
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: