From dcef58e481f6117f1a23a399e64de7f78db3e227 Mon Sep 17 00:00:00 2001 From: jkh Date: Sat, 9 May 1998 05:23:02 +0000 Subject: Well, nobody objected, so here's my -u (unlink) flag to restore. --- sbin/restore/main.c | 18 +++++++++++------- sbin/restore/restore.8 | 19 +++++++++++++------ sbin/restore/restore.h | 1 + sbin/restore/tape.c | 6 ++++++ sbin/restore/utilities.c | 6 +++++- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/sbin/restore/main.c b/sbin/restore/main.c index 6cb87d8..3bc4e8b3 100644 --- a/sbin/restore/main.c +++ b/sbin/restore/main.c @@ -62,6 +62,7 @@ static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/4/95"; 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; @@ -98,9 +99,9 @@ main(argc, argv) 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) { @@ -155,6 +156,9 @@ main(argc, argv) if (dumpnum <= 0) errx(1, "dump number must be greater than 0"); break; + case 'u': + uflag = 1; + break; case 'v': vflag = 1; break; @@ -289,11 +293,11 @@ static void usage() { (void)fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n", - "restore -i [-chkmvy] [-b blocksize] [-f file] [-s fileno]", - "restore -r [-ckvy] [-b blocksize] [-f file] [-s fileno]", - "restore -R [-ckvy] [-b blocksize] [-f file] [-s fileno]", - "restore -x [-chkmvy] [-b blocksize] [-f file] [-s fileno] [file ...]", - "restore -t [-chkvy] [-b blocksize] [-f file] [-s fileno] [file ...]"); + "restore -i [-chkmuvy] [-b blocksize] [-f file] [-s fileno]", + "restore -r [-ckuvy] [-b blocksize] [-f file] [-s fileno]", + "restore -R [-ckuvy] [-b blocksize] [-f file] [-s fileno]", + "restore -x [-chkmuvy] [-b blocksize] [-f file] [-s fileno] [file ...]", + "restore -t [-chkuvy] [-b blocksize] [-f file] [-s fileno] [file ...]"); done(1); } diff --git a/sbin/restore/restore.8 b/sbin/restore/restore.8 index 97cae95..a38d5b0 100644 --- a/sbin/restore/restore.8 +++ b/sbin/restore/restore.8 @@ -30,7 +30,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)restore.8 8.4 (Berkeley) 5/1/95 -.\" $Id: restore.8,v 1.10 1997/03/11 12:55:16 peter Exp $ +.\" $Id: restore.8,v 1.11 1997/04/29 17:48:58 wollman Exp $ .\" .Dd May 1, 1995 .Dt RESTORE 8 @@ -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 @@ Read from the specified .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 diff --git a/sbin/restore/restore.h b/sbin/restore/restore.h index 8dbcee8..4b3affc 100644 --- a/sbin/restore/restore.h +++ b/sbin/restore/restore.h @@ -47,6 +47,7 @@ extern int dflag; /* print out debugging info */ 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 */ /* diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c index 204d736..6cb9fd1 100644 --- a/sbin/restore/tape.c +++ b/sbin/restore/tape.c @@ -566,6 +566,8 @@ extractfile(name) skipfile(); return (GOOD); } + if (uflag && !Nflag) + (void)unlink(name); if (mkfifo(name, mode) < 0) { fprintf(stderr, "%s: cannot create fifo: %s\n", name, strerror(errno)); @@ -586,6 +588,8 @@ extractfile(name) 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)); @@ -605,6 +609,8 @@ extractfile(name) 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", diff --git a/sbin/restore/utilities.c b/sbin/restore/utilities.c index 6008f7a..5eec4de 100644 --- a/sbin/restore/utilities.c +++ b/sbin/restore/utilities.c @@ -145,7 +145,7 @@ newnode(np) 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; @@ -206,6 +206,10 @@ linkit(existing, new, type) 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) { fprintf(stderr, -- cgit v1.1