# HG changeset patch # User Rik # Date 1582070800 28800 # Node ID ce660f584f00a3abaed9011c2935811d3177b920 # Parent 501553fcf6e2dc10c3d21700a0764be58355e95f rename: throw error if operation fails and nargout == 0 (bug #57830). * dirfns.cc (Frename): Add nargout to DEFUN macro invocation. Rename "err" to "status" in documentation. Document that status variable is -1 if an error is encountered. Based on nargout variable, either throw an error if operation failed, or return status and msg information. * textread.m, delete.m, zip.m, io.tst: Fix BIST tests for new behavior. diff -r 501553fcf6e2 -r ce660f584f00 libinterp/corefcn/dirfns.cc --- a/libinterp/corefcn/dirfns.cc Tue Feb 18 15:58:52 2020 -0800 +++ b/libinterp/corefcn/dirfns.cc Tue Feb 18 16:06:40 2020 -0800 @@ -418,14 +418,14 @@ return ovl (result, status, ""); } -DEFMETHODX ("rename", Frename, interp, args, , +DEFMETHODX ("rename", Frename, interp, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {} rename @var{old} @var{new} -@deftypefnx {} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new}) +@deftypefnx {} {[@var{status}, @var{msg}] =} rename (@var{old}, @var{new}) Change the name of file @var{old} to @var{new}. -If successful, @var{err} is 0 and @var{msg} is an empty string. -Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent +If successful, @var{status} is 0 and @var{msg} is an empty string. +Otherwise, @var{status} is -1 and @var{msg} contains a system-dependent error message. @seealso{movefile, copyfile, ls, dir} @end deftypefn */) @@ -439,6 +439,7 @@ from = octave::sys::file_ops::tilde_expand (from); to = octave::sys::file_ops::tilde_expand (to); + octave_value_list retval; std::string msg; octave::event_manager& evmgr = interp.get_event_manager (); @@ -447,16 +448,22 @@ int status = octave::sys::rename (from, to, msg); - if (status < 0) + evmgr.file_renamed (status >= 0); + + if (nargout == 0) { - evmgr.file_renamed (false); - return ovl (-1.0, msg); + if (status < 0) + error ("rename: operation failed: %s", msg.c_str ()); } else { - evmgr.file_renamed (true); - return ovl (status, ""); + if (status < 0) + retval = ovl (-1.0, msg); + else + retval = ovl (0.0, ""); } + + return retval; } DEFUN (glob, args, ,