Mercurial > hg > octave-nkf
comparison 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 |
comparison
equal
deleted
inserted
replaced
8703:c953a6977be6 | 8704:236ff50db90f |
---|---|
56 | 56 |
57 if (fs) | 57 if (fs) |
58 { | 58 { |
59 if (is_relative) | 59 if (is_relative) |
60 { | 60 { |
61 try | |
62 { | |
63 std::string abs_name | |
64 = octave_env::make_absolute (dir_name, octave_env::getcwd ()); | |
65 | |
66 abs_dir_cache_iterator p = abs_dir_cache.find (abs_name); | |
67 | |
68 if (p != abs_dir_cache.end ()) | |
69 { | |
70 // The directory is in the cache of all directories | |
71 // we have visited (indexed by its absolute name). | |
72 // If it is out of date, initialize it. Otherwise, | |
73 // copy the info from the cache. By doing that, we | |
74 // avoid unnecessary calls to stat that can slow | |
75 // things down tremendously for large directories. | |
76 | |
77 const dir_info& di = p->second; | |
78 | |
79 if (fs.mtime () != di.dir_mtime) | |
80 initialize (); | |
81 else | |
82 *this = di; | |
83 | |
84 return; | |
85 } | |
86 } | |
87 catch (octave_execution_exception) | |
88 { | |
89 // Skip updating if we don't know where we are, but | |
90 // don't treat it as an error. | |
91 | |
92 error_state = 0; | |
93 } | |
94 } | |
95 | |
96 if (fs.mtime () != dir_mtime) | |
97 initialize (); | |
98 } | |
99 else | |
100 { | |
101 std::string msg = fs.error (); | |
102 warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ()); | |
103 } | |
104 } | |
105 | |
106 void | |
107 load_path::dir_info::initialize (void) | |
108 { | |
109 is_relative = ! octave_env::absolute_pathname (dir_name); | |
110 | |
111 file_stat fs (dir_name); | |
112 | |
113 if (fs) | |
114 { | |
115 dir_mtime = fs.mtime (); | |
116 | |
117 get_file_list (dir_name); | |
118 | |
119 try | |
120 { | |
61 std::string abs_name | 121 std::string abs_name |
62 = octave_env::make_absolute (dir_name, octave_env::getcwd ()); | 122 = octave_env::make_absolute (dir_name, octave_env::getcwd ()); |
63 | 123 |
64 abs_dir_cache_iterator p = abs_dir_cache.find (abs_name); | 124 // FIXME -- nothing is ever removed from this cache of |
65 | 125 // directory information, so there could be some resource |
66 if (p != abs_dir_cache.end ()) | 126 // problems. Perhaps it should be pruned from time to time. |
67 { | 127 |
68 // The directory is in the cache of all directories we have | 128 abs_dir_cache[abs_name] = *this; |
69 // visited (indexed by its absolute name). If it is out of | 129 } |
70 // date, initialize it. Otherwise, copy the info from the | 130 catch (octave_execution_exception) |
71 // cache. By doing that, we avoid unnecessary calls to stat | 131 { |
72 // that can slow things down tremendously for large | 132 // Skip updating if we don't know where we are. |
73 // directories. | 133 } |
74 | |
75 const dir_info& di = p->second; | |
76 | |
77 if (fs.mtime () != di.dir_mtime) | |
78 initialize (); | |
79 else | |
80 *this = di; | |
81 | |
82 return; | |
83 } | |
84 } | |
85 | |
86 if (fs.mtime () != dir_mtime) | |
87 initialize (); | |
88 } | |
89 else | |
90 { | |
91 std::string msg = fs.error (); | |
92 warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ()); | |
93 } | |
94 } | |
95 | |
96 void | |
97 load_path::dir_info::initialize (void) | |
98 { | |
99 is_relative = ! octave_env::absolute_pathname (dir_name); | |
100 | |
101 file_stat fs (dir_name); | |
102 | |
103 if (fs) | |
104 { | |
105 dir_mtime = fs.mtime (); | |
106 | |
107 get_file_list (dir_name); | |
108 | |
109 std::string abs_name | |
110 = octave_env::make_absolute (dir_name, octave_env::getcwd ()); | |
111 | |
112 // FIXME -- nothing is ever removed from this cache of directory | |
113 // information, so there could be some resource problems. | |
114 // Perhaps it should be pruned from time to time. | |
115 | |
116 abs_dir_cache[abs_name] = *this; | |
117 } | 134 } |
118 else | 135 else |
119 { | 136 { |
120 std::string msg = fs.error (); | 137 std::string msg = fs.error (); |
121 warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ()); | 138 warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ()); |