How does Drupal check write permissions for a folder? How does Drupal check the write permissions on a folder in Linux?

I am using php5-fpm and the web server is working as the user that owns the Drupal directory and I expect that even with a 700 the directories should be readable and writeable by the PHP process and there should be errors only when nginx itself needs access to files or folders.

Does Drupal just test the file permissions for the other user, or does it attempt to read and write as the PHP process itself? It appears to work only when o+rwx is set on the sites/default/files folder but r-x alone should work.

Can anyone point me to the exact routines that make that check?
You're probably looking for the file_prepare_directory() function:


  Checks that the directory exists and is writable.