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)
Wed, Nov 6, 11:48 AM
Unknown Object (File)
Oct 16 2024, 4:07 PM
Unknown Object (File)
Oct 15 2024, 12:03 AM
Unknown Object (File)
Oct 13 2024, 9:08 PM
Unknown Object (File)
Oct 13 2024, 9:08 PM
Unknown Object (File)
Oct 11 2024, 11:13 AM
Unknown Object (File)
Oct 10 2024, 3:50 PM
Unknown Object (File)
Oct 7 2024, 10:25 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 Skipped
Unit
Tests Skipped
Build Status
Buildable 54515
Build 51404: arc lint + arc unit

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
363

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.