Mercurial > hg > octave-lojdl
changeset 11792:70f6c0b493bc release-3-0-x
Fmkdir: improve compatibility
(transplanted from b6d4c644b4b61ada8f5f7ede36072a9b64005389)
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 24 Jul 2008 13:03:36 -0400 |
parents | 42dfc06588e5 |
children | db5518a14ea4 |
files | src/ChangeLog src/dirfns.cc |
diffstat | 2 files changed, 25 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2008-07-24 John W. Eaton <jwe@octave.org> + + * dirfns.cc (Fmkdir): If directory already exists, return status = + true, but also set error message. + 2008-06-25 David Bateman <dbateman@free.fr> * pr-output.cc (Frats): Print usage if nargin == 0.
--- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -257,16 +257,31 @@ { std::string msg; - int status = file_ops::mkdir (file_ops::tilde_expand (dirname), - 0777, msg); + dirname = file_ops::tilde_expand (dirname); + + file_stat fs (dirname); - if (status < 0) + if (fs && fs.is_dir ()) { + // For compatibility with Matlab, we return true when the + // directory already exists. + retval(2) = "mkdir"; - retval(1) = msg; + retval(1) = "directory exists"; + retval(0) = true; } else - retval(0) = true; + { + int status = file_ops::mkdir (dirname, 0777, msg); + + if (status < 0) + { + retval(2) = "mkdir"; + retval(1) = msg; + } + else + retval(0) = true; + } } else print_usage ();