From 80784c730bd4c8c3399762f8955b54c6f6b4bab7 Mon Sep 17 00:00:00 2001
From: Stelian Pop <stelian@popies.net>
Date: Sat, 8 Jun 2002 07:10:36 +0000
Subject: [PATCH] Added -o flag to restore.

---
 CHANGES               |  7 ++++++-
 THANKS                |  4 +++-
 restore/dirs.c        |  5 +++--
 restore/interactive.c |  4 ++--
 restore/main.c        | 15 +++++++++------
 restore/restore.8.in  | 17 ++++++++++++++---
 restore/restore.h     |  3 ++-
 7 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/CHANGES b/CHANGES
index d7dd61d..e4d4357 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,4 @@
-$Id: CHANGES,v 1.178 2002/06/05 13:29:12 stelian Exp $
+$Id: CHANGES,v 1.179 2002/06/08 07:10:36 stelian Exp $
 
 Changes between versions 0.4b28 and 0.4b29 (released ??????????????)
 ====================================================================
@@ -38,6 +38,11 @@ Changes between versions 0.4b28 and 0.4b29 (released ??????????????)
 	of the inode being dumped, but this could evolve in future versions
 	to include interesting debugging output.
 
+8.	Added a -o flag to restore, which automatically restores the current
+	directory permissions in -i or -x mode, without asking the operator
+	whether to do so. Patch submitted by Tony Clayton <tonyc@e-smith.com>
+	and Peter Samuel <peters@e-smith.com>.
+
 Changes between versions 0.4b27 and 0.4b28 (released April 12, 2002)
 ====================================================================
 
diff --git a/THANKS b/THANKS
index cc4dde5..7ad8f54 100644
--- a/THANKS
+++ b/THANKS
@@ -1,4 +1,4 @@
-$Id: THANKS,v 1.59 2002/05/17 08:10:43 stelian Exp $
+$Id: THANKS,v 1.60 2002/06/08 07:10:37 stelian Exp $
 
 Dump and restore were written by the people of the CSRG at the University
 of California, Berkeley.
@@ -30,6 +30,7 @@ Stephen Carr		sgcarr@civeng.adelaide.edu.au
 Rob Cermak		cermak@ahab.rutgers.edu
 Isaac Chuang		ike@isl.stanford.edu
 Rainer Clasen		bj@ncc.cicely.de
+Tony Clayton		tonyc@e-smith.com
 W. Reilly Cooley	wcooley@nakedape.cc
 Chris Danis		screechco@home.com
 Abhijit Dasgupta	abhijit@ans.net
@@ -74,6 +75,7 @@ Dave Platt		dplatt@snulbug.mtview.ca.us
 Kenneth Porter		shiva@well.com
 Graham Reed		greed@users.sourceforge.net
 Bernhard Sadlowski	sadlowsk@Mathematik.Uni-Bielefeld.DE
+Peter Samuel		peters@e-smith.com
 Jan Sanislo		oystr@cs.washington.edu
 Jörg Schilling		schilling@fokus.gmd.de
 Patrik Schindler	poc@pocnet.net
diff --git a/restore/dirs.c b/restore/dirs.c
index 45d4cbe..4a0a2bc 100644
--- a/restore/dirs.c
+++ b/restore/dirs.c
@@ -46,7 +46,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-	"$Id: dirs.c,v 1.18 2002/02/04 11:18:46 stelian Exp $";
+	"$Id: dirs.c,v 1.19 2002/06/08 07:10:37 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -647,7 +647,8 @@ setdirmodes(int flags)
 				ep->e_flags &= ~NEW;
 				continue;
 			}
-			if (node.ino == ROOTINO &&
+			if ((flags & FORCE) == 0 &&
+			    node.ino == ROOTINO &&
 		   	    reply("set owner/mode for '.'") == FAIL)
 				continue;
 		}
diff --git a/restore/interactive.c b/restore/interactive.c
index f252fc8..1f00b2a 100644
--- a/restore/interactive.c
+++ b/restore/interactive.c
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-	"$Id: interactive.c,v 1.23 2002/02/25 13:54:53 stelian Exp $";
+	"$Id: interactive.c,v 1.24 2002/06/08 07:10:37 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -211,7 +211,7 @@ loop:
 			goto bad;
 		createfiles();
 		createlinks();
-		setdirmodes(0);
+		setdirmodes(oflag ? FORCE : 0);
 		if (dflag)
 			checkrestore();
 		volno = 0;
diff --git a/restore/main.c b/restore/main.c
index dc875be..2f2db7a 100644
--- a/restore/main.c
+++ b/restore/main.c
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-	"$Id: main.c,v 1.39 2002/06/05 13:29:15 stelian Exp $";
+	"$Id: main.c,v 1.40 2002/06/08 07:10:37 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -83,7 +83,7 @@ static const char rcsid[] =
 
 int	aflag = 0, bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0;
 int	hflag = 1, mflag = 1, Mflag = 0, Nflag = 0, Vflag = 0, zflag = 0;
-int	uflag = 0, lflag = 0, Lflag = 0;
+int	uflag = 0, lflag = 0, Lflag = 0, oflag = 0;
 char	*Afile = NULL;
 int	dokerberos = 0;
 char	command = '\0';
@@ -166,7 +166,7 @@ main(int argc, char *argv[])
 #ifdef KERBEROS
 		"k"
 #endif
-		"lL:mMN"
+		"lL:mMNo"
 #ifdef USE_QFA
 		"P:Q:"
 #endif
@@ -258,6 +258,9 @@ main(int argc, char *argv[])
 		case 'N':
 			Nflag = 1;
 			break;
+		case 'o':
+			oflag = 1;
+			break;
 #ifdef USE_QFA
 		case 'Q':
 			gTapeposfile = optarg;
@@ -530,7 +533,7 @@ main(int argc, char *argv[])
 		}
 		createfiles();
 		createlinks();
-		setdirmodes(0);
+		setdirmodes(oflag ? FORCE : 0);
 		if (dflag)
 			checkrestore();
 #ifdef DEBUG_QFA
@@ -619,7 +622,7 @@ usage(void)
 		"usage:"
 		"\t%s -C [-cd" kerbflag "lMvVy] [-b blocksize] [-D filesystem] [-f file]\n"
 		"\t%s    [-F script] [-L limit] [-s fileno]\n"
-		"\t%s -i [-acdh" kerbflag "lmMuvVy] [-A file] [-b blocksize] [-f file]\n"
+		"\t%s -i [-acdh" kerbflag "lmMouvVy] [-A file] [-b blocksize] [-f file]\n"
 		"\t%s    [-F script] " qfaflag "[-s fileno]\n"
 #ifdef USE_QFA
 		"\t%s -P file [-acdh" kerbflag "lmMuvVy] [-A file] [-b blocksize]\n"
@@ -631,7 +634,7 @@ usage(void)
 		"\t%s    [-s fileno] [-T directory]\n"
 		"\t%s -t [-cdh" kerbflag "lMuvVy] [-A file] [-b blocksize] [-f file]\n"
 		"\t%s    [-F script] " qfaflag "[-s fileno] [-X filelist] [file ...]\n"
-		"\t%s -x [-acdh" kerbflag "lmMuvVy] [-A file] [-b blocksize] [-f file]\n"
+		"\t%s -x [-acdh" kerbflag "lmMouvVy] [-A file] [-b blocksize] [-f file]\n"
 		"\t%s    [-F script] " qfaflag "[-s fileno] [-X filelist] [file ...]\n",
 		__progname, white, 
 		__progname, white, 
diff --git a/restore/restore.8.in b/restore/restore.8.in
index 74c182e..4dbaece 100644
--- a/restore/restore.8.in
+++ b/restore/restore.8.in
@@ -29,7 +29,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"	$Id: restore.8.in,v 1.26 2002/06/05 13:29:15 stelian Exp $
+.\"	$Id: restore.8.in,v 1.27 2002/06/08 07:10:37 stelian Exp $
 .\"
 .Dd __DATE__
 .Dt RESTORE 8
@@ -50,7 +50,7 @@
 .Op Fl T Ar directory
 .Nm restore
 .Fl i
-.Op Fl acdhklmMNuvVy
+.Op Fl acdhklmMNouvVy
 .Op Fl A Ar file
 .Op Fl b Ar blocksize
 .Op Fl f Ar file
@@ -99,7 +99,7 @@
 .Op file ...
 .Nm restore
 .Fl x
-.Op Fl adchklmMNuvVy
+.Op Fl adchklmMNouvVy
 .Op Fl A Ar file
 .Op Fl b Ar blocksize
 .Op Fl f Ar file
@@ -468,6 +468,17 @@ to perform a full execution as requested by one of
 or
 .Fl x
 command without actually writing any file on disk.
+.It Fl o
+The
+.Fl o
+flag causes
+.Nm
+to automatically restore the current directory permissions
+without asking the operator whether to do so in one of
+.Fl i
+or
+.Fl x
+modes.
 .It Fl Q Ar file
 Use the file
 .Ar file
diff --git a/restore/restore.h b/restore/restore.h
index 572a1bc..6c45e8b 100644
--- a/restore/restore.h
+++ b/restore/restore.h
@@ -5,7 +5,7 @@
  *	Stelian Pop <stelian@popies.net>, 1999-2000
  *	Stelian Pop <stelian@popies.net> - Alcôve <www.alcove.com>, 2000-2002
  *
- *	$Id: restore.h,v 1.25 2002/02/04 11:18:46 stelian Exp $
+ *	$Id: restore.h,v 1.26 2002/06/08 07:10:37 stelian Exp $
  */
 
 /*
@@ -61,6 +61,7 @@ extern int	lflag;		/* assume remote filename is a regular file */
 extern int	Lflag;		/* compare errors limit */
 extern int	mflag;		/* restore by name instead of inode number */
 extern int	Mflag;		/* multi-volume restore */
+extern int	oflag;		/* do restore permissions without asking */
 extern int	Vflag;		/* multi-volume on a single device like CDROM */
 extern int	Nflag;		/* do not write the disk */
 extern int	uflag;		/* unlink symlink targets */
-- 
2.39.5