[Bug 237030] ls -R produces invalid output when recursing dot directories

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Fri Apr 5 02:43:03 UTC 2019


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=237030

            Bug ID: 237030
           Summary: ls -R produces invalid output when recursing dot
                    directories
           Product: Base System
           Version: 11.2-STABLE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: bugs at FreeBSD.org
          Reporter: parakleta at darkreality.org

Created attachment 203394
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=203394&action=edit
Patch to skip recursion of dot directories

`ls -R` doesn't print dot directories (i.e. those with a '.' prefix) nor their
contents but it still recurses through them and will print the contents of
directories within.

The standard could be argued as ambiguous on this point (see bug #206192), but
generally the agreement is that this is the wrong behaviour.  Note additionally
that FreeBSD doesn't exhibit either of the described behaviours because it
doesn't print the contents of a dot directory, only the contents of
non-dot-directories contained in dot-directories.

As an example set up a directory as follows: `mkdir test; cd test; git init`

Then `ls -R` outputs the following:
<-->
    applypatch-msg.sample*     pre-applypatch.sample*     pre-rebase.sample*   
     update.sample*
    commit-msg.sample*         pre-commit.sample*         pre-receive.sample*
    post-update.sample*        pre-push.sample*          
prepare-commit-msg.sample*

    ./.git/info:
    exclude

    ./.git/objects:
    info/ pack/

    ./.git/objects/info:

    ./.git/objects/pack:

    ./.git/refs:
    heads/ tags/

    ./.git/refs/heads:

    ./.git/refs/tags:
<-->

Now run `touch file; ls -R` and the result changes as follows:
<-->
    file

    ./.git/branches:

    ./.git/hooks:
    applypatch-msg.sample*     pre-applypatch.sample*     pre-rebase.sample*   
     update.sample*
    commit-msg.sample*         pre-commit.sample*         pre-receive.sample*
    post-update.sample*        pre-push.sample*          
prepare-commit-msg.sample*

    ./.git/info:
    exclude

    ./.git/objects:
    info/ pack/

    ./.git/objects/info:

    ./.git/objects/pack:

    ./.git/refs:
    heads/ tags/

    ./.git/refs/heads:

    ./.git/refs/tags:
<-->

Notice the extra directories that are now output that weren't before.

The solution is quite simple, to just skip the recursion in the event that the
directory's children are skipped, and attached is a patch which does just that.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list