Well, nobody objected, so here's my -u (unlink) flag to restore.

This commit is contained in:
Jordan K. Hubbard 1998-05-09 05:23:02 +00:00
parent a6919ef89d
commit 2640840497
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=35852
5 changed files with 36 additions and 14 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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 */
/*

View File

@ -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",

View File

@ -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,