changeset 19570:ffbd2cc7ca91

savepath: avoid possible error in struct concatenation * savepath.m: Use cellfun to simplify extraction and concatenation of struct elements. Tag warning with ID and disable warning in test.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Jan 2015 12:15:51 -0500
parents 827cc33ae05c
children 3b0a9a832360
files scripts/path/savepath.m
diffstat 1 files changed, 8 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/path/savepath.m	Mon Jan 05 11:36:33 2015 -0500
+++ b/scripts/path/savepath.m	Mon Jan 05 12:15:51 2015 -0500
@@ -107,18 +107,11 @@
 
     ## Determine the path to Octave's user and system wide packages.
     [pkg_user, pkg_system] = pkg ("list");
-    ## Conversion from cell array of structs to cellstr of archprefixes 
-    if (isempty (pkg_user))
-      pkg_user_path = {};
-    else
-      pkg_user_path = {[pkg_user{:}].archprefix};
-    endif
-    if (isempty (pkg_system))
-      pkg_system_path = {};
-    else
-      pkg_system_path = {[pkg_system{:}].archprefix};
-    endif
-    pkg_path = union (pkg_user_path, pkg_system_path);
+
+    ## Conversion from cell array of structs to cellstr of archprefixes.
+    pkg_path = unique (cellfun (@(elt) elt.archprefix,
+                                [pkg_user, pkg_system],
+                                "uniformoutput", false));
 
     ## Rely on Octave's initialization to include the pkg path elements.
     if (! isempty (pkg_path))
@@ -177,7 +170,8 @@
       error ("savepath: could not close savefile after writing, %s", file);
     elseif (nargin == 0)
       warning ("off", "backtrace", "local");
-      warning ("savepath: current path saved to %s", file);
+      warning ("Octave:savepath-local",
+               "savepath: current path saved to %s", file);
     endif
   end_unwind_protect
 
@@ -192,7 +186,6 @@
   path_elements = strcat (ostrsplit (p, pathsep), pathsep);
 endfunction
 
-
 %!test
 %! fname = tempname ();
 %! status = savepath (fname);
@@ -208,6 +201,7 @@
 %!   assert (fid >= 0);
 %!   fclose (fid);
 %!   ## Save path into local .octaverc file
+%!   warning ("off", "Octave:savepath-local");
 %!   status = savepath ();
 %!   assert (status == 0);
 %!   ## Compare old and new versions