From owner-freebsd-bugs Thu Sep 3 23:40:11 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id XAA10009 for freebsd-bugs-outgoing; Thu, 3 Sep 1998 23:40:11 -0700 (PDT) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id XAA09988 for ; Thu, 3 Sep 1998 23:40:08 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.8/8.8.5) id XAA26675; Thu, 3 Sep 1998 23:40:02 -0700 (PDT) Received: from cain.gsoft.com.au (genesi.lnk.telstra.net [139.130.136.161]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id XAA09113 for ; Thu, 3 Sep 1998 23:35:18 -0700 (PDT) (envelope-from doconnor@gsoft.com.au) Received: (from doconnor@localhost) by cain.gsoft.com.au (8.8.8/8.6.9) id QAA09475; Fri, 4 Sep 1998 16:04:11 +0930 (CST) Message-Id: <199809040634.QAA09475@cain.gsoft.com.au> Date: Fri, 4 Sep 1998 16:04:11 +0930 (CST) From: "Daniel O'Connor" Reply-To: doconnor@gsoft.com.au To: FreeBSD-gnats-submit@FreeBSD.ORG X-Send-Pr-Version: 3.2 Subject: bin/7828: Add a command line option to cp to make it never overwrite Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 7828 >Category: bin >Synopsis: Add a command line option to cp to make it never overwrite >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Thu Sep 3 23:40:01 PDT 1998 >Last-Modified: >Originator: Daniel O'Connor >Organization: >Release: FreeBSD 2.2.6-BETA i386 >Environment: Standard 2.2.6 system >Description: This patch adds the '-n' flag to cp which means "don't ever overwrite a file" it is basically copied from the -i stuff when you hit 'n'. It probably has bugs I only took 5 minutes to write it :) >How-To-Repeat: >Fix: Here is the patch diff -ur cp.old/cp.c cp/cp.c --- cp.old/cp.c Wed Jul 15 11:31:06 1998 +++ cp/cp.c Fri Sep 4 15:18:09 1998 @@ -86,7 +86,7 @@ PATH_T to = { to.p_path, "" }; uid_t myuid; -int Rflag, iflag, pflag, rflag, fflag; +int Rflag, iflag, pflag, rflag, fflag, nflag; int myumask; enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE }; @@ -105,7 +105,7 @@ char *target; Hflag = Lflag = Pflag = 0; - while ((ch = getopt(argc, argv, "HLPRfipr")) != -1) + while ((ch = getopt(argc, argv, "HLPRfiprn")) != -1) switch (ch) { case 'H': Hflag = 1; @@ -124,10 +124,12 @@ break; case 'f': fflag = 1; + nflag = 0; iflag = 0; break; case 'i': iflag = 1; + nflag = 0; fflag = 0; break; case 'p': @@ -136,6 +138,11 @@ case 'r': rflag = 1; break; + case 'n': + nflag = 1; + iflag = 0; + fflag = 0; + break; default: usage(); break; Only in cp: cp.o diff -ur cp.old/extern.h cp/extern.h --- cp.old/extern.h Fri Mar 8 17:28:07 1996 +++ cp/extern.h Fri Sep 4 15:21:36 1998 @@ -42,7 +42,7 @@ extern PATH_T to; extern uid_t myuid; -extern int iflag, pflag, fflag, myumask; +extern int iflag, pflag, fflag, nflag, myumask; #include diff -ur cp.old/utils.c cp/utils.c --- cp.old/utils.c Wed Jul 15 11:31:06 1998 +++ cp/utils.c Fri Sep 4 15:25:45 1998 @@ -96,6 +96,12 @@ } } + if (nflag) { + (void)close(from_fd); + (void)fprintf(stderr, "not overwritten\n"); + return (0); + } + if (fflag) { /* remove existing destination file name, * create a new file */ @@ -319,7 +325,7 @@ usage() { (void)fprintf(stderr, "%s\n%s\n", -"usage: cp [-R [-H | -L | -P]] [-f | -i] [-p] src target", -" cp [-R [-H | -L | -P]] [-f | -i] [-p] src1 ... srcN directory"); +"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-p] src target", +" cp [-R [-H | -L | -P]] [-f | -i | -n] [-p] src1 ... srcN directory"); exit(1); } >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message