Mercurial > octave
changeset 25781:e04c56bbbace
isdir.m: Make m-file a legacy function (bug #54489)
* isdir.m: Note that function is not recommended in docstring.
Add 1-time warning about function being obsolete. Add first time
BIST test to provoke and suppress warning.
* scripts/legacy/module.mk, scripts/miscellaneous/module.mk: Move isdir.m from
miscellaneous/ dir to legacy/ dir.
* NEWS: Announce change to legacy function.
* syscalls.cc (Fstat): Add isfolder to @seealso link.
* utils.cc (Fis_absolute_filename, Fis_rooted_relative_filename, Fmake_absolute_filename):
Replace isdir with isfolder in @seealso links.
* uigetdir.m, uigetfile.m, uiputfile.m, which.m, copyfile.m, mkdir.m,
movefile.m, tempdir.m, unpack.m, what.m, __print_parse_opts__.m,
compare_plot_demos.m, rundemos.m, runtests.m: Replace instances of isdir
with isfolder in core Octave.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 13 Aug 2018 12:17:58 -0700 |
parents | 7c5956c45a29 |
children | 0862570da0ae |
files | NEWS libinterp/corefcn/syscalls.cc libinterp/corefcn/utils.cc scripts/gui/uigetdir.m scripts/gui/uigetfile.m scripts/gui/uiputfile.m scripts/help/which.m scripts/legacy/isdir.m scripts/legacy/module.mk scripts/miscellaneous/copyfile.m scripts/miscellaneous/isdir.m scripts/miscellaneous/mkdir.m scripts/miscellaneous/module.mk scripts/miscellaneous/movefile.m scripts/miscellaneous/tempdir.m scripts/miscellaneous/unpack.m scripts/miscellaneous/what.m scripts/plot/util/private/__print_parse_opts__.m scripts/testfun/private/compare_plot_demos.m scripts/testfun/rundemos.m scripts/testfun/runtests.m |
diffstat | 21 files changed, 91 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Mon Aug 13 11:41:17 2018 -0700 +++ b/NEWS Mon Aug 13 12:17:58 2018 -0700 @@ -79,6 +79,7 @@ ---------------------|------------------ findstr | strfind flipdim | flip + isdir | isfolder or dir_in_loadpath isequalwithequalnans | isequaln isstr | ischar setstr | char
--- a/libinterp/corefcn/syscalls.cc Mon Aug 13 11:41:17 2018 -0700 +++ b/libinterp/corefcn/syscalls.cc Mon Aug 13 12:17:58 2018 -0700 @@ -852,7 +852,7 @@ @result{} err = 0 @result{} msg = @end example -@seealso{lstat, ls, dir} +@seealso{lstat, ls, dir, isfolder} @end deftypefn */) { if (args.length () != 1)
--- a/libinterp/corefcn/utils.cc Mon Aug 13 11:41:17 2018 -0700 +++ b/libinterp/corefcn/utils.cc Mon Aug 13 12:17:58 2018 -0700 @@ -840,7 +840,7 @@ doc: /* -*- texinfo -*- @deftypefn {} {} is_absolute_filename (@var{file}) Return true if @var{file} is an absolute filename. -@seealso{is_rooted_relative_filename, make_absolute_filename, isdir} +@seealso{is_rooted_relative_filename, make_absolute_filename, isfolder} @end deftypefn */) { if (args.length () != 1) @@ -861,7 +861,7 @@ doc: /* -*- texinfo -*- @deftypefn {} {} is_rooted_relative_filename (@var{file}) Return true if @var{file} is a rooted-relative filename. -@seealso{is_absolute_filename, make_absolute_filename, isdir} +@seealso{is_absolute_filename, make_absolute_filename, isfolder} @end deftypefn */) { if (args.length () != 1) @@ -885,7 +885,7 @@ system. No check is done for the existence of @var{file}. -@seealso{canonicalize_file_name, is_absolute_filename, is_rooted_relative_filename, isdir} +@seealso{canonicalize_file_name, is_absolute_filename, is_rooted_relative_filename, isfolder} @end deftypefn */) { if (args.length () != 1)
--- a/scripts/gui/uigetdir.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/gui/uigetdir.m Mon Aug 13 12:17:58 2018 -0700 @@ -40,7 +40,7 @@ error ("uigetdir: INIT_PATH and DIALOG_NAME must be string arguments"); endif - if (! isdir (init_path)) + if (! isfolder (init_path)) init_path = fileparts (init_path); endif
--- a/scripts/gui/uigetfile.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/gui/uigetfile.m Mon Aug 13 12:17:58 2018 -0700 @@ -126,7 +126,7 @@ if (len > 2) if (ischar (args{3})) - if (isdir (args{3})) + if (isfolder (args{3})) fdir = args{3}; fname = fext = ""; else
--- a/scripts/gui/uiputfile.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/gui/uiputfile.m Mon Aug 13 12:17:58 2018 -0700 @@ -90,7 +90,7 @@ if (nargin > 2) if (ischar (varargin{3})) - if (isdir (varargin{3})) + if (isfolder (varargin{3})) fdir = varargin{3}; fname = fext = ""; else
--- a/scripts/help/which.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/help/which.m Mon Aug 13 12:17:58 2018 -0700 @@ -54,7 +54,7 @@ endif else if (isempty (m(i).type)) - if (isdir (m(i).file)) + if (isfolder (m(i).file)) printf ("'%s' is the directory %s\n", m(i).name, m(i).file); else
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/legacy/isdir.m Mon Aug 13 12:17:58 2018 -0700 @@ -0,0 +1,66 @@ +## Copyright (C) 2004-2018 Alois Schloegl +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {} {} isdir (@var{f}) +## +## This function is not recommended. Use @code{isfolder} or +## @code{file_in_loadpath} instead. +## +## Return true if @var{f} is a directory and false otherwise. +## +## Compatibility Note: The @sc{matlab} function of the same name will also +## search for @var{f} in the load path directories. To emulate this behavior +## use +## +## @example +## @var{tf} = ! isempty (file_in_loadpath (@var{f})) +## @end example +## +## @seealso{isfolder, file_in_loadpath, exist, stat, is_absolute_filename, is_rooted_relative_filename} +## @end deftypefn + +function retval = isdir (f) + + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:legacy-function", + "isdir is obsolete; use isfolder or dir_in_loadpath instead\n"); + endif + + if (nargin != 1) + print_usage (); + endif + + ## Exist returns an integer but isdir should return a logical. + retval = (exist (f, "dir") == 7); + +endfunction + + +## First test is necessary to provoke 1-time legacy warning +%!test +%! warning ("off", "Octave:legacy-function", "local"); +%! isdir (pwd ()); + +%!assert (isdir (pwd ())) +%!assert (! isdir (tempname ())) + +%!error isdir () +%!error isdir (1, 2)
--- a/scripts/legacy/module.mk Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/legacy/module.mk Mon Aug 13 12:17:58 2018 -0700 @@ -3,6 +3,7 @@ %canon_reldir%_FCN_FILES = \ %reldir%/findstr.m \ %reldir%/flipdim.m \ + %reldir%/isdir.m \ %reldir%/isequalwithequalnans.m \ %reldir%/isstr.m \ %reldir%/setstr.m \
--- a/scripts/miscellaneous/copyfile.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/miscellaneous/copyfile.m Mon Aug 13 12:17:58 2018 -0700 @@ -78,7 +78,7 @@ endif ## If f1 has more than 1 element then f2 must be a directory - isdir = (exist (f2, "dir") != 0); + isdir = isfolder (f2); if (numel (f1) > 1 && ! isdir) error ("copyfile: when copying multiple files, F2 must be a directory"); endif
--- a/scripts/miscellaneous/isdir.m Mon Aug 13 11:41:17 2018 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -## Copyright (C) 2004-2018 Alois Schloegl -## -## This file is part of Octave. -## -## Octave is free software: you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation, either version 3 of the License, or -## (at your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## <https://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {} {} isdir (@var{f}) -## Return true if @var{f} is a directory. -## @seealso{exist, stat, is_absolute_filename, is_rooted_relative_filename} -## @end deftypefn - -function retval = isdir (f) - - if (nargin != 1) - print_usage (); - endif - - ## Exist returns an integer but isdir should return a logical. - retval = (exist (f, "dir") == 7); - -endfunction - - -%!assert (isdir (pwd ())) -%!assert (! isdir ("this is highly unlikely to be a directory name")) - -%!error isdir () -%!error isdir (1, 2)
--- a/scripts/miscellaneous/mkdir.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/miscellaneous/mkdir.m Mon Aug 13 12:17:58 2018 -0700 @@ -71,7 +71,7 @@ status = 1; - if (! isdir (parent)) + if (! isfolder (parent)) [grandparent, name, ext] = fileparts (parent); [status, msg, msgid] = mkdir_recur (grandparent, [name, ext]); endif @@ -90,7 +90,7 @@ %! unwind_protect %! status = mkdir (dir); %! assert (status); -%! assert (isdir (dir)); +%! assert (isfolder (dir)); %! unwind_protect_cleanup %! confirm_recursive_rmdir (false, "local"); %! rmdir (dir1, "s"); @@ -104,7 +104,7 @@ %! setenv ("HOME", tmp_dir); %! status = mkdir ("~/subdir"); %! assert (status); -%! assert (isdir (fullfile (tmp_dir, "subdir"))); +%! assert (isfolder (fullfile (tmp_dir, "subdir"))); %! unwind_protect_cleanup %! rmdir (fullfile (tmp_dir, "subdir")); %! rmdir (tmp_dir);
--- a/scripts/miscellaneous/module.mk Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/miscellaneous/module.mk Mon Aug 13 12:17:58 2018 -0700 @@ -33,7 +33,6 @@ %reldir%/inputParser.m \ %reldir%/inputname.m \ %reldir%/isdeployed.m \ - %reldir%/isdir.m \ %reldir%/isfolder.m \ %reldir%/ismac.m \ %reldir%/ispc.m \
--- a/scripts/miscellaneous/movefile.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/miscellaneous/movefile.m Mon Aug 13 12:17:58 2018 -0700 @@ -87,7 +87,7 @@ endif ## If f1 has more than 1 element f2 must be a directory - isdir = (exist (f2, "dir") != 0); + isdir = isfolder (f2); if (numel (f1) > 1 && ! isdir) error ("movefile: when moving multiple files, F2 must be a directory"); endif
--- a/scripts/miscellaneous/tempdir.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/miscellaneous/tempdir.m Mon Aug 13 12:17:58 2018 -0700 @@ -37,7 +37,7 @@ dirname = [dirname filesep]; endif - if (! isdir (dirname)) + if (! isfolder (dirname)) warning ("tempdir: '%s' does not exist or is not a directory", dirname); endif
--- a/scripts/miscellaneous/unpack.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/miscellaneous/unpack.m Mon Aug 13 12:17:58 2018 -0700 @@ -115,7 +115,7 @@ file = file{1}; endif - if (isdir (file)) + if (isfolder (file)) if (isempty (filetype)) error ("unpack: FILETYPE must be given for a directory"); elseif (! any (strcmpi (filetype, "gunzip")))
--- a/scripts/miscellaneous/what.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/miscellaneous/what.m Mon Aug 13 12:17:58 2018 -0700 @@ -116,7 +116,7 @@ w.oct{end+1} = n; elseif (strcmp (e, mexext ())) w.mex{end+1} = n; - elseif (n(1) == "@" && isdir (fullfile (dir, n))) + elseif (n(1) == "@" && isfolder (fullfile (dir, n))) w.classes{end+1} = n; endif endif
--- a/scripts/plot/util/private/__print_parse_opts__.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/plot/util/private/__print_parse_opts__.m Mon Aug 13 12:17:58 2018 -0700 @@ -275,7 +275,8 @@ "ps", "ps2", "psc", "psc2", "pdf"}))) have_ghostscript = ! isempty (__ghostscript_binary__ ()); if (have_ghostscript) - file_exists = (numel (dir (arg_st.name)) == 1 && ! isdir (arg_st.name)); + file_exists = (numel (dir (arg_st.name)) == 1 + && ! isfolder (arg_st.name)); if (! file_exists) arg_st.append_to_file = false; endif
--- a/scripts/testfun/private/compare_plot_demos.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/testfun/private/compare_plot_demos.m Mon Aug 13 12:17:58 2018 -0700 @@ -86,7 +86,7 @@ unwind_protect addpath (pwd); for n = 1:numel (arg.toolkits) - if (! isdir (fullfile (cwd, arg.toolkits{n}))) + if (! isfolder (fullfile (cwd, arg.toolkits{n}))) mkdir (arg.toolkits{n}); endif cd (arg.toolkits{n});
--- a/scripts/testfun/rundemos.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/testfun/rundemos.m Mon Aug 13 12:17:58 2018 -0700 @@ -38,7 +38,7 @@ do_class_dirs = true; elseif (nargin == 1) dirs = {canonicalize_file_name(directory)}; - if (isempty (dirs{1}) || ! isdir (dirs{1})) + if (isempty (dirs{1}) || ! isfolder (dirs{1})) ## Search for directory name in path if (directory(end) == '/' || directory(end) == '\') directory(end) = []; @@ -82,7 +82,7 @@ endif elseif (f(1) == "@") f = fullfile (directory, f); - if (isdir (f)) + if (isfolder (f)) dirs(end+1) = f; endif endif
--- a/scripts/testfun/runtests.m Mon Aug 13 11:41:17 2018 -0700 +++ b/scripts/testfun/runtests.m Mon Aug 13 12:17:58 2018 -0700 @@ -38,7 +38,7 @@ do_class_dirs = true; elseif (nargin == 1) dirs = {canonicalize_file_name(directory)}; - if (isempty (dirs{1}) || ! isdir (dirs{1})) + if (isempty (dirs{1}) || ! isfolder (dirs{1})) ## Search for directory name in path if (directory(end) == '/' || directory(end) == '\') directory(end) = []; @@ -83,7 +83,7 @@ endif elseif (f(1) == "@") f = fullfile (directory, f); - if (isdir (f)) + if (isfolder (f)) dirs(end+1) = f; endif endif