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

GDK: eachDirRecurse and eachFileRecurse are NOT depth-first

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.11
    • Fix Version/s: 2.4.13
    • Component/s: groovy-jdk
    • Labels:
      None
    • Environment:
      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

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

                Dates

                • Created:
                  Updated:
                  Resolved: