changeset 19116:cc8aaf9c9e33

exist: don't search path for absolute or rooted relative file names * load-path.cc (load_path::do_find_file): If file name is absolute or rooted relative simply check for existence of file. * variables.cc: New tests.
author John W. Eaton <jwe@octave.org>
date Wed, 16 Jul 2014 18:38:55 -0400
parents 87324260043d
children 09eb8a2ddb02
files libinterp/corefcn/load-path.cc libinterp/corefcn/variables.cc
diffstat 2 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/load-path.cc
+++ b/libinterp/corefcn/load-path.cc
@@ -1300,8 +1300,7 @@
     {
       file_stat fs (file);
 
-      if (fs.exists ())
-        return file;
+      return fs.exists () ? file : retval;
     }
   else
     {
--- a/libinterp/corefcn/variables.cc
+++ b/libinterp/corefcn/variables.cc
@@ -663,6 +663,16 @@
 %!error <TYPE must be a string> exist ("a", 1)
 %!error <NAME must be a string> exist (1)
 
+%!test
+%! flist = dir ();
+%! fname = flist(3).name;  ## skip . and ..
+%! assert (exist (fullfile (pwd (), fname), "file"), 2)
+%! assert (exist (fullfile (pwd (), "nonexistentfile"), "file"), 0)
+
+%!assert (exist ("plot.m", "file"), 2);
+%!assert (exist ("./plot.m", "file"), 0);
+%!assert (exist ("./nonexistentfile", "file"), 0);
+%!assert (exist ("nonexistentfile", "file"), 0);
 */
 
 octave_value