Page MenuHomeFreeBSD

cp: Don't rely on FTS_DP to keep track of depth.
ClosedPublic

Authored by des on Mon, Jun 30, 9:12 PM.
Tags
None
Referenced Files
F122739980: D51096.id157778.diff
Mon, Jul 7, 9:28 PM
Unknown Object (File)
Mon, Jul 7, 8:43 AM
Unknown Object (File)
Sun, Jul 6, 3:42 AM
Unknown Object (File)
Wed, Jul 2, 10:28 AM
Subscribers

Details

Summary

In normal operation, we get an FTS_D entry when we enter a directory
and a matching FTS_DP entry when we leave it. However, if an error
occurs either changing to or reading a directory, we may get an FTS_D
entry followed by FTS_DNR or even FTS_ERR instead. Since FTS_ERR can
also occur for non-directory entries, the only reliable way to keep
track of when we leave a directory is to compare fts_level to our own
depth counter.

This fixes a rare assertion when attempting to recursively copy a
directory tree containing a directory which is either not readable or
not searchable.

While here, also add a test case for directory loops.

Fixes: 82fc0d09e8625
Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 65145
Build 62028: arc lint + arc unit

Event Timeline

des requested review of this revision.Mon, Jun 30, 9:12 PM
kevans added inline comments.
bin/cp/tests/cp_test.sh
644

We should probably add another directory that is readable within that would be traversed into *after* src/foo to confirm that we didn't stop at the unreadable directory and that the internal path construction is still accurate after leaving src/foo and entering the next dir.

bin/cp/tests/cp_test.sh
644

We don't control the order of FTS entries. The best we can do is create three or more items in lexicographical (or reverse lexicographical) order, make the middle one unreadable, and hope that the filesystem returns them in either the order of creation (FFS) or lexicographical order (ZFS). Alternatively, we can add an option to have cp pass a comparison function to FTS for reproducibility.

des marked an inline comment as done.Tue, Jul 1, 5:13 PM
kevans added inline comments.
bin/cp/cp.c
319

This is almost worth pulling out into its own helper used both here and in FTS_DP, but I do not insist.

This revision is now accepted and ready to land.Wed, Jul 2, 12:04 AM
This revision was automatically updated to reflect the committed changes.