changeset 22033:98ee8b1ebbeb

run.m: Return to original directory after executing script (bug #48351). * run.m: Don't use make_absolute_filename(). Instead, return to the original directory whenever we find ourselves still in the scriptdir after execution. Put input validation error messages ahead of main body of code.
author Rik <rik@octave.org>
date Sun, 03 Jul 2016 09:21:31 -0700
parents 91611c9e1d81
children 8df31c24dce3
files scripts/miscellaneous/run.m
diffstat 1 files changed, 15 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/run.m	Sat Jul 02 20:47:47 2016 -0700
+++ b/scripts/miscellaneous/run.m	Sun Jul 03 09:21:31 2016 -0700
@@ -59,21 +59,23 @@
   endif
 
   if (! isempty (d))
-    if (exist (d, "dir"))
-      startdir = pwd ();
-      d = make_absolute_filename (d);
-      unwind_protect
-        cd (d);
-        evalin ("caller", sprintf ("source ('%s%s');", f, ext),
-                "rethrow (lasterror ())");
-      unwind_protect_cleanup
-        if (strcmp (d, pwd ()))
-          cd (startdir);
-        endif
-      end_unwind_protect
-    else
+    if (! exist (d, "dir"))
       error ("run: the path %s doesn't exist", d);
     endif
+
+    startdir = pwd ();
+    scriptdir = "";
+    unwind_protect
+      cd (d);
+      scriptdir = pwd ();
+      evalin ("caller", sprintf ("source ('%s%s');", f, ext),
+              "rethrow (lasterror ())");
+    unwind_protect_cleanup
+      if (strcmp (scriptdir, pwd ()))
+        cd (startdir);
+      endif
+    end_unwind_protect
+
   else
     if (! isempty (ext))
       script = which (script);