diff src/load-path.cc @ 8704:236ff50db90f

load-path.cc: catch execution exception in getcwd
author John W. Eaton <jwe@octave.org>
date Mon, 09 Feb 2009 13:23:09 -0500
parents fcf762ba66cf
children 5dd06f19e9be
line wrap: on
line diff
--- a/src/load-path.cc	Mon Feb 09 12:33:47 2009 -0500
+++ b/src/load-path.cc	Mon Feb 09 13:23:09 2009 -0500
@@ -58,28 +58,38 @@
     {
       if (is_relative)
 	{
-	  std::string abs_name
-	    = octave_env::make_absolute (dir_name, octave_env::getcwd ());
-
-	  abs_dir_cache_iterator p = abs_dir_cache.find (abs_name);
-
-	  if (p != abs_dir_cache.end ())
+	  try
 	    {
-	      // The directory is in the cache of all directories we have
-	      // visited (indexed by its absolute name).  If it is out of
-	      // date, initialize it.  Otherwise, copy the info from the
-	      // cache.  By doing that, we avoid unnecessary calls to stat
-	      // that can slow things down tremendously for large
-	      // directories.
+	      std::string abs_name
+		= octave_env::make_absolute (dir_name, octave_env::getcwd ());
+
+	      abs_dir_cache_iterator p = abs_dir_cache.find (abs_name);
+
+	      if (p != abs_dir_cache.end ())
+		{
+		  // The directory is in the cache of all directories
+		  // we have visited (indexed by its absolute name).
+		  // If it is out of date, initialize it.  Otherwise,
+		  // copy the info from the cache.  By doing that, we
+		  // avoid unnecessary calls to stat that can slow
+		  // things down tremendously for large directories.
 
-	      const dir_info& di = p->second;
+		  const dir_info& di = p->second;
+
+		  if (fs.mtime () != di.dir_mtime)
+		    initialize ();
+		  else
+		    *this = di;
 
-	      if (fs.mtime () != di.dir_mtime)
-		initialize ();
-	      else
-		*this = di;
+		  return;
+		}
+	    }
+	  catch (octave_execution_exception)
+	    {
+	      // Skip updating if we don't know where we are, but
+	      // don't treat it as an error.
 
-	      return;
+	      error_state = 0;
 	    }
 	}
 
@@ -106,14 +116,21 @@
 
       get_file_list (dir_name);
 
-      std::string abs_name
-	= octave_env::make_absolute (dir_name, octave_env::getcwd ());
+      try
+	{
+	  std::string abs_name
+	    = octave_env::make_absolute (dir_name, octave_env::getcwd ());
 
-      // FIXME -- nothing is ever removed from this cache of directory
-      // information, so there could be some resource problems.
-      // Perhaps it should be pruned from time to time.
+	  // FIXME -- nothing is ever removed from this cache of
+	  // directory information, so there could be some resource
+	  // problems.  Perhaps it should be pruned from time to time.
 
-      abs_dir_cache[abs_name] = *this;      
+	  abs_dir_cache[abs_name] = *this;
+	}
+      catch (octave_execution_exception)
+	{
+	  // Skip updating if we don't know where we are.
+	}
     }
   else
     {