Mercurial > octave
changeset 28087:9cb04a9e81ec
rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
* dirfns.cc (Frmdir): Change DEFMETHODX macro invocation to include nargout variable.
Check nargout, and for cases where "nargout == 0" and "status" indicates failure,
throw an error. For cases where "nargout > 0", return 3-value octave_value_list
in variable "retval".
* file-io.cc, gzip.cc, dir.m, isfolder.m, mkdir.m, run.m, tar.m,
unpack.m, zip.m, pathdef.m, savepath.m, configure_make.m, install.m,
uninstall.m, getpref.m, setpref.m, pkg.tst, publish.tst, system.tst:
Change calls from "rmdir" to "sts = rmdir" so that an error is not
unecessarily thrown in BIST tests and other clean up code.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 17 Feb 2020 20:02:18 -0800 |
parents | 32af6bb2a120 |
children | 99a1f2ca574b |
files | libinterp/corefcn/dirfns.cc libinterp/corefcn/file-io.cc libinterp/dldfcn/gzip.cc scripts/miscellaneous/dir.m scripts/miscellaneous/isfolder.m scripts/miscellaneous/mkdir.m scripts/miscellaneous/run.m scripts/miscellaneous/tar.m scripts/miscellaneous/unpack.m scripts/miscellaneous/zip.m scripts/path/pathdef.m scripts/path/savepath.m scripts/pkg/private/configure_make.m scripts/pkg/private/install.m scripts/pkg/private/uninstall.m scripts/prefs/getpref.m scripts/prefs/setpref.m test/pkg/pkg.tst test/publish/publish.tst test/system.tst |
diffstat | 20 files changed, 85 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/dirfns.cc Mon Feb 17 20:02:10 2020 -0800 +++ b/libinterp/corefcn/dirfns.cc Mon Feb 17 20:02:18 2020 -0800 @@ -224,7 +224,7 @@ } } -DEFMETHODX ("rmdir", Frmdir, interp, args, , +DEFMETHODX ("rmdir", Frmdir, interp, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {} rmdir @var{dir} @deftypefnx {} {} rmdir (@var{dir}, "s") @@ -250,6 +250,7 @@ std::string dirname = args(0).xstring_value ("rmdir: DIR must be a string"); std::string fulldir = octave::sys::file_ops::tilde_expand (dirname); + octave_value_list retval; int status = -1; std::string msg; @@ -287,10 +288,20 @@ evmgr.file_renamed (status >= 0); - if (status < 0) - return ovl (false, msg, "rmdir"); + if (nargout == 0) + { + if (status < 0) + error ("rmdir: operation failed: %s", msg.c_str ()); + } else - return ovl (true, "", ""); + { + if (status < 0) + retval = ovl (false, msg, "rmdir"); + else + retval = ovl (true, "", ""); + } + + return retval; } DEFUNX ("link", Flink, args, , @@ -567,8 +578,8 @@ %! save (filename{n}, "a"); %! endfor %! else -%! rmdir (tmpdir); -%! error ("Couldn't change to temporary dir"); +%! sts = rmdir (tmpdir); +%! error ("Couldn't change to temporary directory"); %! endif %! else %! error ("Couldn't create temporary directory"); @@ -580,7 +591,7 @@ %! delete (filename{n}); %! endfor %! cd (cwd); -%! rmdir (tmpdir); +%! sts = rmdir (tmpdir); %! assert (result1, {"file1"; "myfile1"}); %! assert (result2, {"myfile1"}); %! assert (result3, {"file1"; "file2"});
--- a/libinterp/corefcn/file-io.cc Mon Feb 17 20:02:10 2020 -0800 +++ b/libinterp/corefcn/file-io.cc Mon Feb 17 20:02:18 2020 -0800 @@ -2890,7 +2890,7 @@ %! assert (tmpdir, tmp_tmpdir); %! assert (tmpfname (1:4), "file"); %! unwind_protect_cleanup -%! rmdir (tmp_tmpdir); +%! sts = rmdir (tmp_tmpdir); %! for i = 1:numel (envvar) %! if (isempty (envdir{i})) %! unsetenv (envvar{i});
--- a/libinterp/dldfcn/gzip.cc Mon Feb 17 20:02:10 2020 -0800 +++ b/libinterp/dldfcn/gzip.cc Mon Feb 17 20:02:18 2020 -0800 @@ -700,7 +700,7 @@ %! test_function (test_dir, z) %! unwind_protect_cleanup %! confirm_recursive_rmdir (false, "local"); -%! rmdir (test_dir, "s"); +%! sts = rmdir (test_dir, "s"); %! end_unwind_protect %! endfor %!endfunction @@ -840,7 +840,7 @@ %! unwind_protect_cleanup %! confirm_recursive_rmdir (false, "local"); %! for idx = 1:numel(out_dirs) -%! rmdir (out_dirs{idx}, "s"); +%! sts = rmdir (out_dirs{idx}, "s"); %! endfor %! end_unwind_protect %!endfunction
--- a/scripts/miscellaneous/dir.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/miscellaneous/dir.m Mon Feb 17 20:02:18 2020 -0800 @@ -224,7 +224,7 @@ %! chdir (orig_dir); %! confirm_recursive_rmdir (false, "local"); %! if (exist (tmp_dir)) -%! rmdir (tmp_dir, "s"); +%! sts = rmdir (tmp_dir, "s"); %! endif %! end_unwind_protect @@ -238,7 +238,7 @@ %! assert (list(1).folder, canonicalize_file_name (tmp_dir)); %! unwind_protect_cleanup %! if (exist (tmp_dir)) -%! rmdir (tmp_dir); +%! sts = rmdir (tmp_dir); %! endif %! end_unwind_protect
--- a/scripts/miscellaneous/isfolder.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/miscellaneous/isfolder.m Mon Feb 17 20:02:18 2020 -0800 @@ -70,8 +70,8 @@ %! addpath (d); %! assert (! isfolder (n)); %! unwind_protect_cleanup -%! try, rmdir (tmp); end_try_catch -%! try, rmpath (d); end_try_catch +%! sts = rmdir (tmp); +%! rmpath (d); %! end_unwind_protect ## Test input validation
--- a/scripts/miscellaneous/mkdir.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/miscellaneous/mkdir.m Mon Feb 17 20:02:18 2020 -0800 @@ -112,7 +112,7 @@ %! assert (isfolder (dir)); %! unwind_protect_cleanup %! confirm_recursive_rmdir (false, "local"); -%! rmdir (dir1, "s"); +%! sts = rmdir (dir1, "s"); %! end_unwind_protect %!test <*53031> @@ -125,8 +125,8 @@ %! assert (status); %! assert (isfolder (fullfile (tmp_dir, "subdir"))); %! unwind_protect_cleanup -%! rmdir (fullfile (tmp_dir, "subdir")); -%! rmdir (tmp_dir); +%! sts = rmdir (fullfile (tmp_dir, "subdir")); +%! sts = rmdir (tmp_dir); %! if (isempty (HOME)) %! unsetenv ("HOME"); %! else
--- a/scripts/miscellaneous/run.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/miscellaneous/run.m Mon Feb 17 20:02:18 2020 -0800 @@ -114,7 +114,7 @@ %! assert (_5yVNhWVJWJn47RKnzxPsyb_, 1337); %! unwind_protect_cleanup %! unlink (test_script); -%! rmdir (tmp_dir); +%! sts = rmdir (tmp_dir); %! end_unwind_protect ## Test function file execution @@ -140,7 +140,7 @@ %! assert (tstval2, true); %! unwind_protect_cleanup %! unlink (test_function); -%! rmdir (tmp_dir); +%! sts = rmdir (tmp_dir); %! path (path_orig); %! end_unwind_protect
--- a/scripts/miscellaneous/tar.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/miscellaneous/tar.m Mon Feb 17 20:02:18 2020 -0800 @@ -149,12 +149,8 @@ %! chdir (orig_dir); %! unlink (tarname); %! confirm_recursive_rmdir (false, "local"); -%! if (exist (dirname)) -%! rmdir (dirname, "s"); -%! endif -%! if (exist (outdir)) -%! rmdir (outdir, "s"); -%! endif +%! sts = rmdir (dirname, "s"); +%! sts = rmdir (outdir, "s"); %! end_unwind_protect ## Test input validation
--- a/scripts/miscellaneous/unpack.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/miscellaneous/unpack.m Mon Feb 17 20:02:18 2020 -0800 @@ -372,7 +372,7 @@ %! unlink (filename); %! unlink ([filename ".orig"]); %! confirm_recursive_rmdir (false, "local"); -%! rmdir (dirname, "s"); +%! sts = rmdir (dirname, "s"); %! end_unwind_protect %! unwind_protect_cleanup %! ## Restore environment variables TMPDIR, TMP
--- a/scripts/miscellaneous/zip.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/miscellaneous/zip.m Mon Feb 17 20:02:18 2020 -0800 @@ -130,7 +130,7 @@ %! unlink ([dirname, filesep, basename, ext]); %! unlink (zipfile); %! unlink ([zipfile ".zip"]); -%! rmdir (dirname); +%! sts = rmdir (dirname); %! end_unwind_protect ## Test input validation
--- a/scripts/path/pathdef.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/path/pathdef.m Mon Feb 17 20:02:18 2020 -0800 @@ -112,7 +112,7 @@ %! assert (! isempty (strfind (p1, tmp_dir))) %! assert (isempty (strfind (p2, tmp_dir))) %! unwind_protect_cleanup -%! rmdir (tmp_dir); +%! sts = rmdir (tmp_dir); %! path (path_orig); %! end_unwind_protect @@ -128,7 +128,7 @@ %! path_2 = path (); %! assert (path_1, path_2) %! unwind_protect_cleanup -%! rmdir (tmp_dir); +%! sts = rmdir (tmp_dir); %! path (path_orig); %! end_unwind_protect
--- a/scripts/path/savepath.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/path/savepath.m Mon Feb 17 20:02:18 2020 -0800 @@ -230,6 +230,6 @@ %! end_unwind_protect %! unwind_protect_cleanup %! confirm_recursive_rmdir (false, "local"); -%! rmdir (test_dir, "s"); +%! sts = rmdir (test_dir, "s"); %! unlink (fname); %! end_unwind_protect
--- a/scripts/pkg/private/configure_make.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/pkg/private/configure_make.m Mon Feb 17 20:02:18 2020 -0800 @@ -83,7 +83,7 @@ cmd = ["cd '" src "'; " scenv "./configure " flags]; [status, output] = shell (cmd, verbose); if (status != 0) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); disp (output); error ("pkg: error running the configure script for %s.", desc.name); endif @@ -100,7 +100,7 @@ [status, output] = shell (sprintf ("%s make --jobs %i --directory '%s'", scenv, jobs, src), verbose); if (status != 0) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); disp (output); error ("pkg: error running 'make' for the %s package.", desc.name); endif
--- a/scripts/pkg/private/install.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/pkg/private/install.m Mon Feb 17 20:02:18 2020 -0800 @@ -145,7 +145,7 @@ catch ## Something went wrong, delete tmpdirs. for i = 1:length (tmpdirs) - rmdir (tmpdirs{i}, "s"); + sts = rmdir (tmpdirs{i}, "s"); endfor rethrow (lasterror ()); end_try_catch @@ -199,7 +199,7 @@ catch ## Something went wrong, delete tmpdirs. for i = 1:length (tmpdirs) - rmdir (tmpdirs{i}, "s"); + sts = rmdir (tmpdirs{i}, "s"); endfor rethrow (lasterror ()); end_try_catch @@ -218,7 +218,7 @@ catch ## Something went wrong, delete tmpdirs. for i = 1:length (tmpdirs) - rmdir (tmpdirs{i}, "s"); + sts = rmdir (tmpdirs{i}, "s"); endfor rethrow (lasterror ()); end_try_catch @@ -237,11 +237,11 @@ catch ## Something went wrong, delete tmpdirs. for i = 1:length (tmpdirs) - rmdir (tmpdirs{i}, "s"); + sts = rmdir (tmpdirs{i}, "s"); endfor for i = 1:length (descriptions) - rmdir (descriptions{i}.dir, "s"); - rmdir (getarchdir (descriptions{i}), "s"); + sts = rmdir (descriptions{i}.dir, "s"); + sts = rmdir (getarchdir (descriptions{i}), "s"); endfor rethrow (lasterror ()); end_try_catch @@ -252,8 +252,8 @@ if (dirempty (descriptions{i}.dir, {"packinfo", "doc"}) && dirempty (getarchdir (descriptions{i}))) warning ("package %s is empty\n", descriptions{i}.name); - rmdir (descriptions{i}.dir, "s"); - rmdir (getarchdir (descriptions{i}), "s"); + sts = rmdir (descriptions{i}.dir, "s"); + sts = rmdir (getarchdir (descriptions{i}), "s"); descriptions(i) = []; endif endfor @@ -282,10 +282,10 @@ catch ## Something went wrong, delete tmpdirs. for i = 1:length (tmpdirs) - rmdir (tmpdirs{i}, "s"); + sts = rmdir (tmpdirs{i}, "s"); endfor for i = 1:length (descriptions) - rmdir (descriptions{i}.dir, "s"); + sts = rmdir (descriptions{i}.dir, "s"); endfor if (global_install) printf ("error: couldn't append to %s\n", global_list); @@ -376,7 +376,7 @@ if (! isfolder (inst_dir)) [status, msg] = mkdir (inst_dir); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("the 'inst' directory did not exist and could not be created: %s", msg); endif @@ -450,7 +450,7 @@ endif [status, output] = copyfile (archindependent, instdir); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("Couldn't copy files from 'src' to 'inst': %s", output); endif endif @@ -465,7 +465,7 @@ endif [status, output] = copyfile (archdependent, archdir); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("Couldn't copy files from 'src' to 'inst': %s", output); endif endif @@ -517,7 +517,7 @@ if (! dirempty (instdir)) [status, output] = copyfile (fullfile (instdir, "*"), desc.dir); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("couldn't copy files to the installation directory"); endif if (isfolder (fullfile (desc.dir, getarch ())) @@ -532,39 +532,39 @@ if (! isfolder (octm3)) [status, output] = mkdir (octm3); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("couldn't create installation directory %s : %s", octm3, output); endif endif [status, output] = mkdir (octm2); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("couldn't create installation directory %s : %s", octm2, output); endif endif [status, output] = mkdir (octm1); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("couldn't create installation directory %s : %s", octm1, output); endif endif [status, output] = mkdir (octfiledir); if (status != 1) - rmdir (desc.dir, "s"); + sts = rmdir (desc.dir, "s"); error ("couldn't create installation directory %s : %s", octfiledir, output); endif endif [status, output] = movefile (fullfile (desc.dir, getarch (), "*"), octfiledir); - rmdir (fullfile (desc.dir, getarch ()), "s"); + sts = rmdir (fullfile (desc.dir, getarch ()), "s"); if (status != 1) - rmdir (desc.dir, "s"); - rmdir (octfiledir, "s"); + sts = rmdir (desc.dir, "s"); + sts = rmdir (octfiledir, "s"); error ("couldn't copy files to the installation directory"); endif endif @@ -575,8 +575,8 @@ packinfo = fullfile (desc.dir, "packinfo"); [status, msg] = mkdir (packinfo); if (status != 1) - rmdir (desc.dir, "s"); - rmdir (octfiledir, "s"); + sts = rmdir (desc.dir, "s"); + sts = rmdir (octfiledir, "s"); error ("couldn't create packinfo directory: %s", msg); endif @@ -596,8 +596,8 @@ write_index (desc, fullfile (packdir, "inst"), fullfile (packinfo, "INDEX"), global_install); catch - rmdir (desc.dir, "s"); - rmdir (octfiledir, "s"); + sts = rmdir (desc.dir, "s"); + sts = rmdir (octfiledir, "s"); rethrow (lasterror ()); end_try_catch endif @@ -629,8 +629,8 @@ else [status, output] = copyfile (filepath, packinfo); if (status != 1) - rmdir (desc.dir, "s"); - rmdir (octfiledir, "s"); + sts = rmdir (desc.dir, "s"); + sts = rmdir (octfiledir, "s"); error ("Couldn't copy %s file: %s", filename, output); endif endif @@ -801,8 +801,8 @@ cd (wd); catch cd (wd); - rmdir (desc.dir, "s"); - rmdir (getarchdir (desc), "s"); + sts = rmdir (desc.dir, "s"); + sts = rmdir (getarchdir (desc), "s"); rethrow (lasterror ()); end_try_catch endif
--- a/scripts/pkg/private/uninstall.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/pkg/private/uninstall.m Mon Feb 17 20:02:18 2020 -0800 @@ -122,6 +122,11 @@ endif endif if (isfolder (desc.dir)) + ## FIXME: If first call to rmdir fails, then error() will + ## stop further processing of getarchdir & archprefix. + ## If this is, in fact, correct, then calls should + ## just be shortened to rmdir (...) and let rmdir() + ## report failure and reason for failure. [status, msg] = rmdir (desc.dir, "s"); if (status != 1 && isfolder (desc.dir)) error ("couldn't delete directory %s: %s", desc.dir, msg); @@ -131,7 +136,7 @@ error ("couldn't delete directory %s: %s", getarchdir (desc), msg); endif if (dirempty (desc.archprefix)) - rmdir (desc.archprefix, "s"); + sts = rmdir (desc.archprefix, "s"); endif else warning ("directory %s previously lost", desc.dir);
--- a/scripts/prefs/getpref.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/prefs/getpref.m Mon Feb 17 20:02:18 2020 -0800 @@ -151,9 +151,7 @@ %! %! unwind_protect_cleanup %! unlink (fullfile (tmp_home, ".octave_prefs")); -%! if (isfolder (tmp_home)) -%! rmdir (tmp_home); -%! endif +%! sts = rmdir (tmp_home); %! if (isempty (HOME)) %! unsetenv ("HOME"); %! else
--- a/scripts/prefs/setpref.m Mon Feb 17 20:02:10 2020 -0800 +++ b/scripts/prefs/setpref.m Mon Feb 17 20:02:18 2020 -0800 @@ -96,9 +96,7 @@ %! "size mismatch for PREF and VAL"); %! unwind_protect_cleanup %! unlink (fullfile (tmp_home, ".octave_prefs")); -%! if (isfolder (tmp_home)) -%! rmdir (tmp_home); -%! endif +%! sts = rmdir (tmp_home); %! if (isempty (HOME)) %! unsetenv ("HOME"); %! else
--- a/test/pkg/pkg.tst Mon Feb 17 20:02:10 2020 -0800 +++ b/test/pkg/pkg.tst Mon Feb 17 20:02:18 2020 -0800 @@ -31,6 +31,11 @@ %!shared old_prefix, old_archprefix, old_local_list, old_global_list, prefix, restorecfg, restorecache, restoreglobalcache, rmtmpdir, mfile_pkg_name, mfile_pkg_tgz +%!function test_cleanup (prefix) +%! confirm_recursive_rmdir (0, "local"); +%! sts = rmdir (prefix, "s"); +%!endfunction + %!testif HAVE_Z %! ## Do all tests in a temporary directory %! [old_prefix, old_archprefix] = pkg ("prefix"); @@ -48,7 +53,7 @@ %! pkg ("prefix", prefix, prefix); %! pkg ("local_list", fullfile (prefix, "octave_packages")); %! pkg ("global_list", fullfile (prefix, "octave_packages")); -%! rmtmpdir = @onCleanup (@() confirm_recursive_rmdir (0, "local") && rmdir (prefix, "s")); +%! rmtmpdir = @onCleanup (@() test_cleanup (prefix)); %! %! ## Create tar.gz file packages of testing directories in prefix directory %! mfile_pkg_name = {"mfile_basic_test", "mfile_minimal_test"};
--- a/test/publish/publish.tst Mon Feb 17 20:02:10 2020 -0800 +++ b/test/publish/publish.tst Mon Feb 17 20:02:18 2020 -0800 @@ -49,7 +49,7 @@ %! publish (fname{1}, opts); %! endfor %! confirm_recursive_rmdir (false, "local"); -%! rmdir (tmpDir, "s"); +%! sts = rmdir (tmpDir, "s"); %! unwind_protect_cleanup %! set (0, "defaultfigurevisible", visibility); %! graphics_toolkit (toolkit); @@ -81,7 +81,7 @@ %! str1 = fileread ("test_script.m"); %! str2 = grabcode (fullfile (tmpDir, "test_script.html")); %! confirm_recursive_rmdir (false, "local"); -%! rmdir (tmpDir, "s"); +%! sts = rmdir (tmpDir, "s"); %! ## Canonicalize strings %! str1 = strjoin (deblank (strsplit (str1, "\n")), "\n"); %! str2 = strjoin (deblank (strsplit (str2, "\n")), "\n");
--- a/test/system.tst Mon Feb 17 20:02:10 2020 -0800 +++ b/test/system.tst Mon Feb 17 20:02:18 2020 -0800 @@ -104,7 +104,7 @@ %!test %! crr = confirm_recursive_rmdir (); %! confirm_recursive_rmdir (0); -%! assert (!rmdir ("foo", "s")); +%! assert (! rmdir ("foo", "s")); %! confirm_recursive_rmdir (crr); %!test