changeset 9105:9b12ed1fbbbd

force rehash if path, addpath, or rmpath modify path
author John W. Eaton <jwe@octave.org>
date Wed, 08 Apr 2009 23:18:05 -0400
parents e0250e2b60ed
children 1eb5b24186b6
files src/ChangeLog src/load-path.cc
diffstat 2 files changed, 35 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Apr 08 13:16:23 2009 +0200
+++ b/src/ChangeLog	Wed Apr 08 23:18:05 2009 -0400
@@ -1,3 +1,9 @@
+2009-04-08  John W. Eaton  <jwe@octave.org>
+
+	* load-path.cc (rehash_internal): New function.
+	(Frehash): Use it.
+	(Fpath, Faddpath, Frmpath): Call rehash_internal if path is modified.
+
 2009-04-08  Jaroslav Hajek  <highegg@gmail.com>
 
 	* xpow.cc (elem_xpow (double, const Range&),
--- a/src/load-path.cc	Wed Apr 08 13:16:23 2009 +0200
+++ b/src/load-path.cc	Wed Apr 08 23:18:05 2009 -0400
@@ -1817,6 +1817,18 @@
   return retval;
 }
 
+static void
+rehash_internal (void)
+{
+  load_path::update ();
+
+  // FIXME -- maybe we should rename this variable since it is being
+  // used for more than keeping track of the prompt time.
+
+  // This will force updated functions to be found.
+  Vlast_prompt_time.stamp ();
+}
+
 DEFUN (rehash, , ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} rehash ()\n\
@@ -1825,13 +1837,7 @@
 {
   octave_value_list retval;
 
-  load_path::update ();
-
-  // FIXME -- maybe we should rename this variable since it is being
-  // used for more than keeping track of the prompt time.
-
-  // This will force updated functions to be found.
-  Vlast_prompt_time.stamp ();
+  rehash_internal ();
 
   return retval;
 }
@@ -1909,6 +1915,8 @@
 	    path += dir_path::path_sep_str () + argv[i];
 
 	  load_path::set (path, true);
+
+	  rehash_internal ();
 	}
 
       if (nargout > 0)
@@ -1991,6 +1999,8 @@
 	    }
 	}
 
+      bool need_to_update = false;
+
       for (int i = 0; i < nargin; i++)
 	{
 	  std::string arg = args(i).string_value ();
@@ -2012,11 +2022,16 @@
 		    load_path::append (dir, true);
 		  else
 		    load_path::prepend (dir, true);
+
+		  need_to_update = true;
 		}
 	    }
 	  else
 	    error ("addpath: expecting all args to be character strings");
 	}
+
+      if (need_to_update)
+	rehash_internal ();
     }
   else
     print_usage ();
@@ -2044,6 +2059,8 @@
 
   if (nargin > 0)
     {
+      bool need_to_update = false;
+
       for (int i = 0; i < nargin; i++)
 	{
 	  std::string arg = args(i).string_value ();
@@ -2063,11 +2080,16 @@
 
 		  if (! load_path::remove (dir))
 		    warning ("rmpath: %s: not found", dir.c_str ());
+		  else
+		    need_to_update = true;
 		}
 	    }
 	  else
 	    error ("addpath: expecting all args to be character strings");
 	}
+
+      if (need_to_update)
+	rehash_internal ();
     }
   else
     print_usage ();