File chosen via Qt OSX dialog not writeable() but writes() in sandbox!

This is strangeness I encountered while porting my Python Qt app to OSX, sandboxed.

After getting a filename using a QFileDialog, my code was preflighting: checking whether the file was writeable, before actually trying to write it.  I checked using QFileInfo().  My check said the file was NOT writeable.

Then I changed the code to try the write, and only check whether the file was writeable as part of error reporting when an exception was thrown by the write.  Strangely, the write succeeds.

A filename obtained using QFileDialog should be sandbox safe, since it uses a native dialog, the native dialog is part of the sandbox mechanism, and since the user has chosen the file the sandbox mechanism should let you write the file.  (Sidenote: Qt docs and other bug reports explain that it only works if you provide a default filename to QFileDialog.)

I think my check for writeable is flawed: directory is writeable OR (file exists AND file is writeable.) In this case, the user does not have permission to write the directory (Documents) and the file does not exist yet.  Now I am wondering if there is a way to preflight file creation properly.  Sandboxing complicates it.

Leave a comment