From nobody Wed Jan 17 18:28:33 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TFZBn3zFSz56P0B; Wed, 17 Jan 2024 18:28:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TFZBn3TlZz4c0Z; Wed, 17 Jan 2024 18:28:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705516113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7e5zpCQI3dZ1x0HqHlxPYX8YYtckzP9o2YUjUM2E93Y=; b=M9W442Vh0LxE1hafExhMx3iE3rBzYFQSZ60T+wGLgPjsW6GGLXg/IWYNw7M5D70FABbYEL icbHVb40NrAcQNhFjoZ/sJ5yE4fNFfLpIZr/i5NkM0KzHe2qKQHWxpC+jhGx1joxBz54VY JDZeriXWhOPoUwQVBOvm+PD0uQCX9Bd8IwUTLkcwXZWK7yC4X215DBA5QAGFC1fm9++YOs MHljVE/1+esLkXzMvpUEpsob/7pZfISHnPTg7xtepuqpYF6GTALWyMcUVgRrDU2UX2x3cu q6erAeIuYD7DSFK/CuFEkRHhIzNdB1Wyq03EsD9qU7kQcnbeKoxlIqoDRKMbiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705516113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7e5zpCQI3dZ1x0HqHlxPYX8YYtckzP9o2YUjUM2E93Y=; b=KM8PAn82hY0Pf5AuBNHUEesrmyLch7RXsuKBp7IBcwQyAMDySdekxU1giVALRKHhH3AKZ+ kL8eLuFl+TMY1BbleZlU4x2Y/Kje1DKpKOG+dNSYBus6nMfHjRKrexUYuQ4kBQ0ThG18Dm pV1KEGNh/ocMCHSCsyw1PGQ0QpI/QnIxiYBFITULGITBzJ/FQeighZs00kJZLYMreTbNco DG297pPFEUVLUx1Ph5ZOjJGpmshZwGWwQkO5Q1sJ3F3jEf6ZqIY+lCh8Ek8EfgUpQhfLH2 gAZhi8K7Cev5VpB9OukuJd0jdfjqk6vRJULcyko7gB/Z220462wJ6FWR0INOyg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705516113; a=rsa-sha256; cv=none; b=CER6/znQaiP9T6XDmPP/MmkUCQtRJukRkBypU0fcBjIBAk7HSiE9iNgVM8wscgE69nOfSz 5dMX9NFHq0zpjb00Pu4pCRNe3Qx6zUl9MgFlkdaT5hhzkLxCW2cp7qd9S5zD4a0IuiI7Y/ I06yhqrxef7mPiB5WA1AUdFAy0R5Ui3dufzp4mdtKgxIWnXUh2O+kCJ2Iabo8ZF6Xnsaz6 oXTTC40uBVeTpcqsXaG/V4s2Woea2Q/iUsFv7c4zrz074EHzhqXkUC+1I0nbdz5AeePsf5 uiqTUyOg86amBxippM3fQiUOuo8V83NG7ZVaBVOWSOQgZd3xe/H7kCg1/+1C0g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TFZBn2X0hzZ0v; Wed, 17 Jan 2024 18:28:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40HISXMK063233; Wed, 17 Jan 2024 18:28:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40HISXFo063230; Wed, 17 Jan 2024 18:28:33 GMT (envelope-from git) Date: Wed, 17 Jan 2024 18:28:33 GMT Message-Id: <202401171828.40HISXFo063230@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 0fcf3a6235ee - stable/14 - cp: Add -N flag, inspired by NetBSD's similar flag List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 0fcf3a6235eefde0c31a4dc6e16241319468fad9 Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=0fcf3a6235eefde0c31a4dc6e16241319468fad9 commit 0fcf3a6235eefde0c31a4dc6e16241319468fad9 Author: Warner Losh AuthorDate: 2023-12-07 19:32:27 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-01-17 18:28:22 +0000 cp: Add -N flag, inspired by NetBSD's similar flag 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 Differential Revision: https://reviews.freebsd.org/D42673 (cherry picked from commit 5a52e3d00dd5e0209f6fcb1e41b5985191e6f4e7) cp: Don't warn for chflags() failing with EOPNOTSUPP if flags == 0 From NetBSD's utils.c 1.5 importing importing BSDI change, with light formatting changes: Author: cgd 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 Info: utils.c 1.6 Obtained from: NetBSD Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D42674 (cherry picked from commit 3e7e3b5bdf902a375decc11b95179fd2fbc0da2a) --- bin/cp/cp.1 | 14 +++++++++----- bin/cp/cp.c | 7 +++++-- bin/cp/extern.h | 2 +- bin/cp/utils.c | 15 ++++++++++++--- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/bin/cp/cp.1 b/bin/cp/cp.1 index b67718bd39b1..3862babafe7f 100644 --- a/bin/cp/cp.1 +++ b/bin/cp/cp.1 @@ -31,7 +31,7 @@ .\" .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" -.Dd February 23, 2022 +.Dd December 7, 2023 .Dt CP 1 .Os .Sh NAME @@ -44,7 +44,7 @@ .Op Fl H | Fl L | Fl P .Oc .Op Fl f | i | n -.Op Fl alpsvx +.Op Fl alNpsvx .Ar source_file target_file .Nm .Oo @@ -52,15 +52,15 @@ .Op Fl H | Fl L | Fl P .Oc .Op Fl f | i | n -.Op Fl alpsvx +.Op Fl alNpsvx .Ar source_file ... target_directory .Nm .Op Fl f | i | n -.Op Fl alPpsvx +.Op Fl alNPpsvx .Ar source_file target_file .Nm .Op Fl f | i | n -.Op Fl alPpsvx +.Op Fl alNPpsvx .Ar source_file ... target_directory .Sh DESCRIPTION In the first synopsis form, the @@ -90,6 +90,10 @@ option is specified, symbolic links on the command line are followed. If the .Fl R option is specified, all symbolic links are followed. +.It Fl N +When used with +.Fl p , +suppress copying file flags. .It Fl P No symbolic links are followed. This is the default if the diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 24156e4b4a0b..8217a1e5d3c9 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -84,7 +84,7 @@ static char emptystring[] = ""; PATH_T to = { to.p_path, emptystring, "" }; -int fflag, iflag, lflag, nflag, pflag, sflag, vflag; +int Nflag, fflag, iflag, lflag, nflag, pflag, sflag, vflag; static int Hflag, Lflag, Rflag, rflag; volatile sig_atomic_t info; @@ -103,7 +103,7 @@ main(int argc, char *argv[]) fts_options = FTS_NOCHDIR | FTS_PHYSICAL; Pflag = 0; - while ((ch = getopt(argc, argv, "HLPRafilnprsvx")) != -1) + while ((ch = getopt(argc, argv, "HLNPRafilnprsvx")) != -1) switch (ch) { case 'H': Hflag = 1; @@ -113,6 +113,9 @@ main(int argc, char *argv[]) Lflag = 1; Hflag = Pflag = 0; break; + case 'N': + Nflag = 1; + break; case 'P': Pflag = 1; Hflag = Lflag = 0; diff --git a/bin/cp/extern.h b/bin/cp/extern.h index a5b86c12b2f9..2b302db7fff4 100644 --- a/bin/cp/extern.h +++ b/bin/cp/extern.h @@ -38,7 +38,7 @@ typedef struct { } PATH_T; extern PATH_T to; -extern int fflag, iflag, lflag, nflag, pflag, sflag, vflag; +extern int Nflag, fflag, iflag, lflag, nflag, pflag, sflag, vflag; extern volatile sig_atomic_t info; __BEGIN_DECLS diff --git a/bin/cp/utils.c b/bin/cp/utils.c index 02d78350067c..f43902eab3e6 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -355,13 +355,22 @@ setfile(struct stat *fs, int fd) rval = 1; } - if (!gotstat || fs->st_flags != ts.st_flags) + if (!Nflag && (!gotstat || fs->st_flags != ts.st_flags)) if (fdval ? fchflags(fd, fs->st_flags) : (islink ? lchflags(to.p_path, fs->st_flags) : chflags(to.p_path, fs->st_flags))) { - warn("chflags: %s", to.p_path); - rval = 1; + /* + * 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.) + */ + if (errno != EOPNOTSUPP || fs->st_flags != 0) { + warn("chflags: %s", to.p_path); + rval = 1; + } } return (rval);