# HG changeset patch # User Markus Mützel # Date 1683363393 -7200 # Node ID 632f9b828de1d8529ddfc6e99a0ff251533a1605 # Parent ed3a18fe328a5685b4aad630714ed4db6e570397 Avoid using file_stat in liboctave/util (bug #59711). * cmd-edit.cc (looks_like_filename), cmd-hist.cc (gnu_history::do_append), kpse.cc (kpse_element_dir), oct-glob.cc (glob, windows_glob), url-transfer.cc (base_url_transfer::mget_directory): Use functions "dir_exists" or "file_exists" instead of "file_stat". * kpse.cc (dir_p), oct-glob.cc (single_match_exists): Remove unused static functions. diff -r ed3a18fe328a -r 632f9b828de1 liboctave/util/cmd-edit.cc --- a/liboctave/util/cmd-edit.cc Fri May 05 19:49:23 2023 +0200 +++ b/liboctave/util/cmd-edit.cc Sat May 06 10:56:33 2023 +0200 @@ -37,6 +37,7 @@ #include "file-ops.h" #include "file-stat.h" #include "lo-error.h" +#include "lo-sysdep.h" #include "lo-utils.h" #include "oct-env.h" #include "oct-mutex.h" @@ -550,9 +551,7 @@ candidate_filename = sys::file_ops::tilde_expand (candidate_filename); - sys::file_stat fs (candidate_filename); - - retval = fs.is_dir (); + retval = sys::dir_exists (candidate_filename); } } diff -r ed3a18fe328a -r 632f9b828de1 liboctave/util/cmd-hist.cc --- a/liboctave/util/cmd-hist.cc Fri May 05 19:49:23 2023 +0200 +++ b/liboctave/util/cmd-hist.cc Sat May 06 10:56:33 2023 +0200 @@ -371,8 +371,7 @@ std::string hist_dir = sys::file_ops::dirname (f); if (! hist_dir.empty ()) { - sys::file_stat fs (hist_dir); - if (! fs.is_dir () + if (! sys::dir_exists (hist_dir) && (sys::recursive_mkdir (hist_dir, 0777) < 0)) (*current_liboctave_error_handler) ("%s: Could not create directory \"%s\" for history", @@ -411,9 +410,7 @@ if (! f.empty ()) { - sys::file_stat fs (f); - - if (! fs) + if (! sys::file_exists (f)) { std::ofstream tmp = sys::ofstream (f, std::ios::out); tmp.close (); diff -r ed3a18fe328a -r 632f9b828de1 liboctave/util/kpse.cc --- a/liboctave/util/kpse.cc Fri May 05 19:49:23 2023 +0200 +++ b/liboctave/util/kpse.cc Sat May 06 10:56:33 2023 +0200 @@ -45,6 +45,7 @@ #include "file-ops.h" #include "file-stat.h" #include "kpse.h" +#include "lo-sysdep.h" #include "oct-env.h" #include "oct-password.h" #include "oct-time.h" @@ -54,8 +55,6 @@ #if defined (OCTAVE_USE_WINDOWS_API) # define WIN32_LEAN_AND_MEAN 1 # include - -# include "lo-sysdep.h" #endif // Define the characters which separate components of filenames and @@ -1015,17 +1014,6 @@ return c; } -/* Return true if FN is a directory or a symlink to a directory, - false if not. */ - -static bool -dir_p (const std::string& fn) -{ - octave::sys::file_stat fs (fn); - - return (fs && fs.is_dir ()); -} - /* Given a path element ELT, return a the element with a trailing slash or an empty string if the element is not a directory. @@ -1042,7 +1030,7 @@ if (elt.empty ()) return ret; - if (dir_p (elt)) + if (octave::sys::dir_exists (elt)) { ret = elt; diff -r ed3a18fe328a -r 632f9b828de1 liboctave/util/oct-glob.cc --- a/liboctave/util/oct-glob.cc Fri May 05 19:49:23 2023 +0200 +++ b/liboctave/util/oct-glob.cc Sat May 06 10:56:33 2023 +0200 @@ -53,14 +53,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -static bool -single_match_exists (const std::string& file) -{ - sys::file_stat s (file); - - return s.exists (); -} - OCTAVE_BEGIN_NAMESPACE(sys) bool @@ -121,7 +113,7 @@ if (n > 1 || (n == 1 - && single_match_exists (std::string (matches[0])))) + && sys::file_exists (std::string (matches[0])))) { retval.resize (k+n); @@ -371,7 +363,7 @@ if (n > 1 || (n == 1 - && single_match_exists (std::string (matches[0])))) + && sys::file_exists (std::string (matches[0])))) { retval.resize (k + n); diff -r ed3a18fe328a -r 632f9b828de1 liboctave/util/url-transfer.cc --- a/liboctave/util/url-transfer.cc Fri May 05 19:49:23 2023 +0200 +++ b/liboctave/util/url-transfer.cc Sat May 06 10:56:33 2023 +0200 @@ -75,9 +75,8 @@ const std::string& target) { std::string sep = sys::file_ops::dir_sep_str (); - sys::file_stat fs (directory); - if (! fs || ! fs.is_dir ()) + if (! sys::dir_exists (directory)) { std::string msg; int status = sys::mkdir (directory, 0777, msg); @@ -175,9 +174,7 @@ std::string realfile = realdir + sys::file_ops::dir_sep_str () + file; - sys::file_stat fs (realfile); - - if (! fs.exists ()) + if (! sys::file_exists (realfile)) { m_ok = false; m_errmsg = "__ftp__mput: file '" + realfile @@ -185,7 +182,7 @@ break; } - if (fs.is_dir ()) + if (sys::dir_exists (realfile)) { file_list.append (mput_directory (realdir, file));