Page MenuHomeFreeBSD

cp: Add -N flag, inspired by NetBSD's similar flag
ClosedPublic

Authored by imp on Nov 19 2023, 5:29 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Jul 4, 7:04 AM
Unknown Object (File)
Tue, Jul 2, 1:14 PM
Unknown Object (File)
Thu, Jun 27, 6:39 PM
Unknown Object (File)
Wed, Jun 26, 10:58 PM
Unknown Object (File)
Mon, Jun 24, 5:38 PM
Unknown Object (File)
Thu, Jun 20, 8:33 PM
Unknown Object (File)
May 8 2024, 7:40 AM
Unknown Object (File)
May 8 2024, 7:40 AM
Subscribers

Details

Summary

Add -N to supress copying of file flags when -p is specified (explicitly
or implicitly). Often times we don't care about the flags or wish to be
able to copy to NFS, and this comes in handy for that. FreeBSD's and
NetBSD's cp are somewhat different, so I had to reimplement all but one
of the patch hunks...

Obtained from: NetBSD (cp.1 1.25, cp.c 1.37, utils.c 1.28 by elad)
Sponsored by: Netflix

Diff Detail

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

Event Timeline

imp requested review of this revision.Nov 19 2023, 5:29 AM
imp created this revision.

Note that NetBSD also will suppress the chflags error when it is EOPNOTSUPP and flags != 0...
This might be useful for us as well...
I don't know if that's the problem we're hitting in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=275030 since it's self reported that uarch is set which is super weird unless there's some 3rd party archiver running (not a standard situation, but not one that's crazy to do and one we likely should support).
But that might also be useful.

Peter Wemm's changes tried to fix this, but maybe something weird is going on, since ts.st_flags should == 0 making this equivalent to enami-san check, no?

commit 4faaa03777b10915d6a69cd44732a3d75be8e7ed
Author: Peter Wemm <peter@FreeBSD.org>
Date:   Wed Jun 10 06:29:23 1998 +0000

Don't attempt to change owner/mode/flags that don't need to changed.
This should calm down attempts to `cp -p' to a nfs mount or some other
filesystem that doesn't accept flags or all combinations of flags.

It will warn if it fails to change flags though.

see below for when it arrived in NetBSD

bin/cp/utils.c
357

NetBSD also has:
if (errno != EOPNOTSUPP || fs->st_flags != 0) {
}

around the warn and rval setting. That's also likely good: chflags(0) for no flags isn't really a failure...

Oh wait, the EOPNOTSUPP is from BSDI via NetBSD:

Author: cgd <cgd@NetBSD.org>
Date:   Wed Feb 26 14:40:51 1997 +0000

Patch from BSDI (via Keith Bostic):
>NFS doesn't support chflags; ignore errors unless there's reason
>to believe we're losing bits.  (Note, this still won't be right
>if the server supports flags and we were trying to *remove* flags
>on a file that we copied, i.e., that we didn't create.)

CVS rev utils.c 1.6

Note: There's nothing similar in gnu cp, but it also doesn't use the -N flag for anything.

This revision was not accepted when it landed; it landed in state Needs Review.Dec 7 2023, 8:38 PM
This revision was automatically updated to reflect the committed changes.