From 70a05c8ee8129941c801bb0e6bc93ea8e42bc254 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Sat, 24 Aug 2013 22:43:43 +0300 Subject: Avoid OS X sandbox messages when just checking if a pathname is a directory Calling stat() on an arbitrary directory doesn't cause any sandbox violation, it seems, even if the process has no access to that directory. Calling opendir() on it is a sandbox violation. Change-Id: I776c04653cbeeb511a4a1e455fcc2b10ed4a0e5c --- ucb/source/ucp/file/shell.cxx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'ucb') diff --git a/ucb/source/ucp/file/shell.cxx b/ucb/source/ucp/file/shell.cxx index b9c0390551ed..a9cd7e44ad81 100644 --- a/ucb/source/ucp/file/shell.cxx +++ b/ucb/source/ucp/file/shell.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include + +#include + #include #include "osl/diagnose.h" #include @@ -2074,6 +2078,23 @@ sal_Bool SAL_CALL shell::ensuredir( sal_Int32 CommandId, else aPath = rUnqPath; +#if HAVE_FEATURE_MACOSX_SANDBOX + + // Avoid annoying sandbox messages in the system.log from the + // below aDirectory.open(), which ends up calling opendir(). + // Surely it is easier to just call stat()? Calling stat() on an + // arbitrary (?) directory does not seem to cause any sandbox + // violation, while opendir() does. (Sorry I could not be bothered + // to use some complex cross-platform abstraction over stat() here + // in this OS X specific code block.) + + OUString aDirName; + struct stat s; + if( osl::FileBase::getSystemPathFromFileURL( aPath, aDirName ) == osl::FileBase::E_None && + stat(OUStringToOString( aDirName, RTL_TEXTENCODING_UTF8).getStr(), &s ) == 0 && + S_ISDIR( s.st_mode ) ) + return sal_True; +#endif // HACK: create directory on a mount point with nobrowse option // returns ENOSYS in any case !! -- cgit