Page MenuHomeFreeBSD

find(1): Don't skip unreadable directories in -depth mode
Needs ReviewPublic

Authored by tavianator_tavianator.com on Mar 4 2021, 9:38 PM.
Tags
None
Referenced Files
Unknown Object (File)
Dec 27 2023, 6:43 AM
Unknown Object (File)
Sep 26 2023, 5:32 AM
Unknown Object (File)
Sep 11 2023, 10:25 PM
Unknown Object (File)
Aug 26 2023, 5:18 PM
Unknown Object (File)
Jun 15 2023, 10:36 PM
Unknown Object (File)
Mar 30 2023, 4:43 AM
Unknown Object (File)
Mar 22 2023, 7:59 AM
Unknown Object (File)
Mar 4 2023, 9:28 PM

Details

Reviewers
pstef
Summary

find -depth skips unreadable directories, while find without -depth
prints them. For example:

$ mkdir -p foo/bar
$ chmod -r foo
$ find foo -depth 2>/dev/null
foo
$ find foo 2>/dev/null
foo
foo/bar

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

Test Plan

Added a test to find_test.sh.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
No Test Coverage
Build Status
Buildable 41765
Build 38654: arc lint + arc unit

Event Timeline

Added a test to find_test.sh. The test fails when run as root though.

See how usr.sbin/extattr/tests/extattr_test.sh or tests/sys/cddl/zfs/tests/cli_user/misc/misc_test.sh use the unprivileged user.

@tavianator_tavianator.com this worked for me, could you check?

atf_test_case find_depth_error
find_depth_error_head()
{
	atf_set "descr" "Verifies that unreadable directories are still " \
	    "reported in -depth mode"
	atf_set "require.user" "unprivileged"
}
find_depth_error_body()
{
	atf_check -s exit:0 mkdir -p test/dir
	atf_check -s exit:0 chmod -r test

	atf_check -s exit:1 -o "inline:test\n" -e ignore find test -depth
	atf_check -s exit:1 -o "inline:test\n" -e ignore find test
}
pstef requested changes to this revision.Sep 24 2021, 8:26 PM
This revision now requires changes to proceed.Sep 24 2021, 8:26 PM

Make sure the test uses an unprivileged user

usr.bin/find/tests/find_test.sh
80–81

These seem to be copied from another test case.

82

With the way test/dir was setup above, I don't get that output. Here it's merely "test\n" on stdout.

Write the comment instead of copy-pasting it

tavianator_tavianator.com added inline comments.
usr.bin/find/tests/find_test.sh
82

Right but I did chmod -r test/dir and you did chmod -r test. I can change it to yours if you want.

usr.bin/find/tests/find_test.sh
82

I don't have a preference here, at least not yet. I did chmod -r test because the example both in the description of this differential and your comment in the PR do chmod -r foo and not chmod -r foo/bar. Maybe we could go for the most coverage, testing all four cases, if that makes sense to you.