Mercurial > hg > octave-lojdl
changeset 7970:b6d4c644b4b6
Fmkdir: improve compatibility
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 24 Jul 2008 13:03:36 -0400 |
parents | 4f9e8eeb2059 |
children | dd5cc5016487 |
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-07-23 John W. Eaton <jwe@octave.org> * ov-usr_fcn.cc (octave_user_function::do_multi_index_op):
--- 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 ();