Historically, BSD cp has followed symbolic links in the destination
when copying recursively, while GNU cp has not. POSIX is somewhat
vague on the topic, but both interpretations are within bounds. In
33ad990ce9, cp was changed to apply the same logic for symbolic
links in the destination as for symbolic links in the source: follow
if not recursing (which is moot, as this situation can only arise
while recursing) or if the `-L` option was given. There is no support
for this in POSIX. We can either switch back, or go all the way.
Having carefully weighed the kind of trouble you can run into by
following unexpected symlinks up against the kind of trouble you can
run into by not following symlinks you expected to follow, we choose
to go all the way.
Note that this means we need to stat the destination twice: once,
following links, to check if it is or references the same file as the
source, and a second time, not following links, to set the dne flag
and determine the destination's type.
While here, remove a needless complication in the dne logic. We don't
need to explicitly reject overwriting a directory with a non-directory,
because it will fail anyway.
Finally, add test cases for copying a directory to a symlink and
overwriting a directory with a non-directory.
MFC after: never
Relnotes: yes
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D44578
While here add CAVEAT section and promote the use of printf(1)
Reviewed by: gbe@, imp@
Approved by: manpages (gbe)
Differential Revision: https://reviews.freebsd.org/D43493
* Give link(1) its own usage message.
* Use getprogname(3) instead of rolling our own.
* Verify that the target file does not already exist.
* Add tests specific to link(1).
MFC after: 3 days
Sponsored by: Klara, Inc.
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D44635
* When copying a directory, if the destination exists and is not a
directory, we would previously emit an error message and exit. The
correct behavior according to POSIX is to emit an error message and
continue without descending further into the source directory.
* When copying a directory, if the destination does not exist and we
fail to create it, we would previously emit an error message and
exit. The correct behavior according to POSIX is to emit an error
message and continue. Whether to descend further into the source
directory is explicitly left unspecified; GNU cp does not, which
seems to me to be the safer and less surprising option, so let's not
either.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D44577
The "gethost" program should be built with the host compiler.
Obtained from: Juniper Networks, Inc.
Reviewed by: sjg
Differential Revision: https://reviews.freebsd.org/D44537
Program:
* Add a dummy getopt(3) loop to handle `--`.
* Move interval parsing out into a separate function.
* Print a diagnostic for every invalid interval.
* Check for NaN and infinity.
* Improve bounds checks.
Manual page:
* Miscellaneous markup fixes.
* Reword DESCRIPTION section.
* Move text about GNU compatibility to STANDARDS section.
* Convert examples from csh to sh.
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D44471
Both wcount and wresid are ssize_t so this cast is not needed. Just
remove it so the code is easier to read.
Signed-off-by: Collin Funk <collin.funk1@gmail.com>
Reviewed by: emaste, zlei
Pull Request: https://github.com/freebsd/freebsd-src/pull/1116
The cleanup of d854370fa8 had a cut and paste error (so f_verssort
was set to 1 and then to 0 rather thame f_timesort being set to 0).
Fixes: d854370fa8
Sponsored by: Netflix
Capability rights passed to cap_rights_* are not simple bitmaks and
cannot be ORed together in general (although it will work for certain
subsets of rights).
PR: 277057
Reported by: asomers, markj
- Adding a missing verb "is" on line 723
- Changing is to are on line 835
Event: Advanced UNIX Programming Course (Fall’23) at NTHU.
Pull Request: https://github.com/freebsd/freebsd-src/pull/986
Note that the error diagnostic can now be printed both to stderr due to
the absence of the -f flag and to stdout due to SIGINFO simultaneously.
Noted and reviewed by: jrtc27
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
As stated in the man page, -f must not emit warning on error, and must
not set the utility exit code.
PR: 276723
Github PR: https://github.com/freebsd/freebsd-src/pull/1088
Reviewed by: imp, kib
MFC after: 1 week
This uses more generic wording in the FreeBSD installer, when offering
the user to use the system booted without running the installer.
The updated wording is also reflected in freebsd-version(1).
Reviewed by: emaste
Sponsored by: The FreeBSD Foundation
Differential revision: https://reviews.freebsd.org/D43233
On the manpage of df(1), "according" is mistyped into "acccording"
Event: Advanced UNIX Programming Course (Fall'23) at NTHU.
Signed-off-by: Pin-Yi Kuo <kuokuoyiyi@gapp.nthu.edu.tw>
Reviewed by: imp, zlei, Mina Galić
Pull Request: https://github.com/freebsd/freebsd-src/pull/944
This accidentally got left out of 0f4467ce44.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans, allanjude
Differential Revision: https://reviews.freebsd.org/D43067
If the destination file exists but we decide unlink it, set the dne
flag. This means we don't need to re-check the conditions that would
have caused us to delete the file when we later need to decide whether
to create or replace it.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D43064
- The HLPR flags are grouped together at the beginning because they are
the standard flags for programs using FTS. Move the N flag out from
among them to its correct place in the sequence.
- The Pflag variable isn't used outside main(), but moving it out lets
us skip initialization and keeps it with its friends H, L and R.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D43063
This test case tests two different things: first, that copying a symlink
results in a file with the same contents as the target of the symlink,
rather than a second symlink, and second, that cp will refuse to copy a
file to itself, or to a link to itself, or a link to its target. Leave
the first part in basic_symlink, move the second part to a new test case
named samefile, and slightly expand both cases.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D43062
Rewrite `copy_file()` so the lflag and sflag are handled as early as
possible instead of constantly checking that they're not set and then
handling them at the end. This also opens the door to changing the
failure logic at some future point (for instance, we might decide to
fall back to copying if `errno` indicates that the file system does not
support links).
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans, allanjude
Differential Revision: https://reviews.freebsd.org/D43055