diff src/dirfns.cc @ 5640:426719471ac6

[project @ 2006-03-04 06:02:14 by jwe]
author jwe
date Sat, 04 Mar 2006 06:02:14 +0000
parents acbcb9f164ca
children 7ba9ad1fec11
line wrap: on
line diff
--- a/src/dirfns.cc	Fri Mar 03 16:39:35 2006 +0000
+++ b/src/dirfns.cc	Sat Mar 04 06:02:14 2006 +0000
@@ -53,6 +53,7 @@
 #include "dirfns.h"
 #include "error.h"
 #include "gripes.h"
+#include "input.h"
 #include "oct-obj.h"
 #include "pager.h"
 #include "procstream.h"
@@ -62,6 +63,10 @@
 #include "utils.h"
 #include "variables.h"
 
+// TRUE means we ask for confirmation before recursively removing a
+// directory tree.
+static bool Vconfirm_recursive_rmdir = true;
+
 // XXX FIXME XXX -- changing the plotter directory should be handled
 // by registering a function for octave_env::chdir to call so that
 // this function can be eliminated.
@@ -350,7 +355,7 @@
 \n\
 If the optional second parameter is suplied, recursively remove all\n\
 subdirectories as well.\n\
-@seealso{mkdir}\n\
+@seealso{mkdir, confirm_recursive_rmdir}\n\
 @end deftypefn")
 {
   octave_value_list retval;
@@ -369,19 +374,32 @@
 	gripe_wrong_type_arg ("rmdir", args(0));
       else
 	{
+	  std::string fulldir = file_ops::tilde_expand (dirname);
+	  int status = -1;
 	  std::string msg;
 
-	  std::string fulldir = file_ops::tilde_expand (dirname);
-
 	  if (nargin == 2)
 	    {
 	      if (args(1).string_value () == "s")
-		status = file_ops::recursive_rmdir (fulldir, msg);
+		{
+		  bool doit = true;
+
+		  if (interactive && Vconfirm_recursive_rmdir)
+		    {
+		      std::string prompt
+			= "remove entire contents of " + fulldir + "? ";
+
+		      doit = octave_yes_or_no (prompt);
+		    }
+
+		  if (doit)
+		    status = file_ops::recursive_rmdir (fulldir, msg);
+		}
 	      else
 		error ("rmdir: expecting second argument to be \"s\"");
 	    }
 	  else
-	    status = file_ops::rmdir (fulldir, msg)
+	    status = file_ops::rmdir (fulldir, msg);
 
 	  if (status < 0)
 	    {
@@ -669,9 +687,25 @@
   return retval;
 }
 
+static int
+confirm_recursive_rmdir (void)
+{
+  Vconfirm_recursive_rmdir = check_preference ("confirm_recursive_rmdir");
+
+  return 0;
+}
+
 void
 symbols_of_dirfns (void)
 {
+  DEFVAR (confirm_recursive_rmdir, true, confirm_recursive_rmdir,
+    "-*- texinfo -*-\n\
+@defvr {Built-in Variable} confirm_recursive_rmdir\n\
+If the value of @code{confirm_recursive_rmdir} is nonzero, Octave\n\
+will ask for confirmation before recursively removing a directory tree.\n\
+The default value is 0.\n\
+@end defvr");
+
   DEFCONST (filesep, file_ops::dir_sep_str,
     "-*- texinfo -*-\n\
 @defvr {Built-in Variable} filesep\n\