Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 07 May 1998 23:44:55 -0700
From:      "Jordan K. Hubbard" <jkh@time.cdrom.com>
To:        hackers@FreeBSD.ORG
Subject:   Would anyone object to the following new flag to restore (-u)
Message-ID:  <13220.894609895@time.cdrom.com>

next in thread | raw e-mail | index | archive | help
It does what --unlink does for tar: Make sure that the target doesn't
exist before doing an operation that could cause a warning diagnostic
to be generated (e.g a symlink() or mknod() call with a pre-existing
target).  Sometimes you really want this behavior when you're using,
for example, dump/restore back-to-back in order to clone a system disk
to a backup drive.  Unless you want to newfs the backup drive each and
every time (which wouldn't allow you to do incremental dumps to it
either), you're going to get a faceful of diagnostics every time from
restore which only serve to obscure any real errors that may be
occuring.  Anyway, if there are no serious objections to this in the
next 24 hours or so, I'll commit these changes:

Index: main.c
===================================================================
RCS file: /home/ncvs/src/sbin/restore/main.c,v
retrieving revision 1.2.2.3
diff -u -u -r1.2.2.3 main.c
--- main.c	1997/10/15 18:33:33	1.2.2.3
+++ main.c	1998/05/08 05:23:03
@@ -61,6 +61,7 @@
 
 int	bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0;
 int	hflag = 1, mflag = 1, Nflag = 0;
+int	uflag = 0;
 int	dokerberos = 0;
 char	command = '\0';
 long	dumpnum = 1;
@@ -97,9 +98,9 @@
 		inputdev = _PATH_DEFTAPE;
 	obsolete(&argc, &argv);
 #ifdef KERBEROS
-#define	optlist "b:cdf:hikmNRrs:tvxy"
+#define	optlist "b:cdf:hikmNRrs:tuvxy"
 #else
-#define	optlist "b:cdf:himNRrs:tvxy"
+#define	optlist "b:cdf:himNRrs:tuvxy"
 #endif
 	while ((ch = getopt(argc, argv, optlist)) != -1)
 		switch(ch) {
@@ -154,6 +155,9 @@
 			if (dumpnum <= 0)
 				errx(1, "dump number must be greater than 0");
 			break;
+		case 'u':
+			uflag = 1;
+			break;
 		case 'v':
 			vflag = 1;
 			break;
@@ -289,10 +293,10 @@
 {
 	(void)fprintf(stderr, "usage:\t%s%s%s%s%s",
 	    "restore tfhksvy [file ...]\n",
-	    "\trestore xfhkmsvy [file ...]\n",
-	    "\trestore ifhkmsvy\n",
-	    "\trestore rfksvy\n",
-	    "\trestore Rfksvy\n");
+	    "\trestore xfhkmsuvy [file ...]\n",
+	    "\trestore ifhkmsuvy\n",
+	    "\trestore rfksvuy\n",
+	    "\trestore Rfksvuy\n");
 	done(1);
 }
 
Index: restore.8
===================================================================
RCS file: /home/ncvs/src/sbin/restore/restore.8,v
retrieving revision 1.5.2.3
diff -u -u -r1.5.2.3 restore.8
--- restore.8	1997/10/15 18:33:33	1.5.2.3
+++ restore.8	1998/05/08 06:26:59
@@ -41,32 +41,32 @@
 .Sh SYNOPSIS
 .Nm restore
 .Fl i
-.Op Fl chkmvy
+.Op Fl chkmuvy
 .Op Fl b Ar blocksize
 .Op Fl f Ar file
 .Op Fl s Ar fileno
 .Nm restore
 .Fl R
-.Op Fl ckvy
+.Op Fl ckuvy
 .Op Fl b Ar blocksize
 .Op Fl f Ar file
 .Op Fl s Ar fileno
 .Nm restore
 .Fl r
-.Op Fl ckvy
+.Op Fl ckuvy
 .Op Fl b Ar blocksize
 .Op Fl f Ar file
 .Op Fl s Ar fileno
 .Nm restore
 .Fl t
-.Op Fl chkvy
+.Op Fl chkuvy
 .Op Fl b Ar blocksize
 .Op Fl f Ar file
 .Op Fl s Ar fileno
 .Op file ...
 .Nm restore
 .Fl x
-.Op Fl chkmvy
+.Op Fl chkmuvy
 .Op Fl b Ar blocksize
 .Op Fl f Ar file
 .Op Fl s Ar fileno
@@ -316,6 +316,13 @@
 .Ar fileno
 on a multi-file tape.
 File numbering starts at 1.
+.It Fl u
+When creating certain types of files, restore may generate a warning
+diagnostic if they already exist in the target directory.
+To prevent this, the
+.Fl u
+(unlink) flag causes restore to remove old entries before attempting
+to create new ones.
 .It Fl v
 Normally
 .Nm restore
Index: restore.h
===================================================================
RCS file: /home/ncvs/src/sbin/restore/restore.h,v
retrieving revision 1.1.1.1
diff -u -u -r1.1.1.1 restore.h
--- restore.h	1994/05/26 06:33:54	1.1.1.1
+++ restore.h	1998/05/08 05:30:06
@@ -47,6 +47,7 @@
 extern int	hflag;		/* restore heirarchies */
 extern int	mflag;		/* restore by name instead of inode number */
 extern int	Nflag;		/* do not write the disk */
+extern int	uflag;		/* unlink symlink targets */
 extern int	vflag;		/* print out actions taken */
 extern int	yflag;		/* always try to recover from tape errors */
 /*
Index: tape.c
===================================================================
RCS file: /home/ncvs/src/sbin/restore/tape.c,v
retrieving revision 1.4.2.5
diff -u -u -r1.4.2.5 tape.c
--- tape.c	1998/05/02 09:19:51	1.4.2.5
+++ tape.c	1998/05/08 06:19:46
@@ -552,6 +552,8 @@
 		return (linkit(lnkbuf, name, SYMLINK));
 
 	case IFIFO:
+		if (uflag && !Nflag)
+			(void)unlink(name);
 		if (mkfifo(name, mode) < 0) {
 			fprintf(stderr, "%s: cannot create FIFO: %s\n",
 				name, strerror(errno));
@@ -571,6 +573,8 @@
 			skipfile();
 			return (GOOD);
 		}
+		if (uflag)
+			(void)unlink(name);
 		if (mknod(name, mode, (int)curfile.dip->di_rdev) < 0) {
 			fprintf(stderr, "%s: cannot create special file: %s\n",
 			    name, strerror(errno));
@@ -589,6 +593,8 @@
 			skipfile();
 			return (GOOD);
 		}
+		if (uflag)
+			(void)unlink(name);
 		if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
 		    0666)) < 0) {
 			fprintf(stderr, "%s: cannot create file: %s\n",
Index: utilities.c
===================================================================
RCS file: /home/ncvs/src/sbin/restore/utilities.c,v
retrieving revision 1.2
diff -u -u -r1.2 utilities.c
--- utilities.c	1995/05/30 06:09:56	1.2
+++ utilities.c	1998/05/08 06:38:47
@@ -145,7 +145,7 @@
 	if (np->e_type != NODE)
 		badentry(np, "newnode: not a node");
 	cp = myname(np);
-	if (!Nflag && mkdir(cp, 0777) < 0) {
+	if (!Nflag && mkdir(cp, 0777) < 0 && !uflag) {
 		np->e_flags |= EXISTED;
 		fprintf(stderr, "warning: %s: %s\n", cp, strerror(errno));
 		return;
@@ -205,6 +205,10 @@
 	char *existing, *new;
 	int type;
 {
+
+	/* if we want to unlink first, do it now so *link() won't fail */
+	if (uflag && !Nflag)
+		(void)unlink(new);
 
 	if (type == SYMLINK) {
 		if (!Nflag && symlink(existing, new) < 0) {



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?13220.894609895>