Page MenuHomeFreeBSD

cp: fix some cases with infinite recursion
ClosedPublic

Authored by kevans on Jan 19 2022, 5:06 AM.
Tags
None
Referenced Files
F142428551: D33944.id.diff
Mon, Jan 19, 9:27 PM
F142407916: D33944.id101632.diff
Mon, Jan 19, 5:29 PM
F142399214: D33944.id.diff
Mon, Jan 19, 2:56 PM
Unknown Object (File)
Sun, Jan 18, 4:54 PM
Unknown Object (File)
Sun, Jan 18, 1:25 PM
Unknown Object (File)
Dec 13 2025, 2:23 PM
Unknown Object (File)
Nov 27 2025, 5:46 AM
Unknown Object (File)
Nov 24 2025, 11:23 PM
Subscribers

Details

Summary

As noted in the PR, cp -R has some surprising behavior. Typically, when
you cp -R foo bar where both foo and bar exist, foo is cleanly copied
to foo/bar. When you cp -R foo foo (where foo clearly exists), cp(1)
goes a little off the rails as it creates foo/foo, then discovers that
and creates foo/foo/foo, so on and so forth, until it eventually fails.

POSIX doesn't seem to disallow this behavior, but it isn't very useful.
GNU cp(1) will detect the recursion and squash it, but emit a message in
the process that it has done so.

This change seemingly follows the GNU behavior, but it currently doesn't
warn about the situation -- the author feels that the final product is
about what one might expect from doing this and thus, doesn't need a
warning. The author doesn't feel strongly about this.

PR: 235438

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable