# HG changeset patch # User John W. Eaton # Date 1216919016 14400 # Node ID 70f6c0b493bc4dadd1c8003852d1c14735fce949 # Parent 42dfc06588e535072b4a3db8062e1ab6de64a4e0 Fmkdir: improve compatibility (transplanted from b6d4c644b4b61ada8f5f7ede36072a9b64005389) diff -r 42dfc06588e5 -r 70f6c0b493bc src/ChangeLog --- a/src/ChangeLog Thu Jul 31 05:53:02 2008 -0400 +++ b/src/ChangeLog Thu Jul 24 13:03:36 2008 -0400 @@ -1,3 +1,8 @@ +2008-07-24 John W. Eaton + + * dirfns.cc (Fmkdir): If directory already exists, return status = + true, but also set error message. + 2008-06-25 David Bateman * pr-output.cc (Frats): Print usage if nargin == 0. diff -r 42dfc06588e5 -r 70f6c0b493bc src/dirfns.cc --- a/src/dirfns.cc Thu Jul 31 05:53:02 2008 -0400 +++ b/src/dirfns.cc Thu Jul 24 13:03:36 2008 -0400 @@ -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 ();