Skip to content

[bug] Keep counting directories when recursion is disabled #20

@thiagodp

Description

@thiagodp

Method _stat calls _emitDir when a directory is found, even when recursion is disabled, and this makes the counter dirs to accumulate the number of analyzed directories.

For instance, let's suppose that we have a directory foo with the subdirectories bar and zoo:

foo/
    |_ bar/
         |_ file1.jpg
    |_ zoo/
    |_ file1.txt
    |_ file2.txt

A recursive walk in foo makes filewalker.dirs to be 3, correctly.
However, a non-recursive walk in foo also makes filewalker.dirs to be 3, instead of being 1.

Here the method _stat compares whether the entry is a directory and then it calls _emitDir. I think it can be changed to the following comparison:

if ( s.isDirectory() && ( this.recursive || ! this.recursive && this.dirs < 1 ) ) {
   // ... (same as currently)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions