diff --git a/includes/file.inc b/includes/file.inc index 7ec13f3..b7059b1 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -447,7 +447,7 @@ function file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS) return FALSE; } // The directory exists, so check to see if it is writable. - $writable = is_writable($directory); + $writable = file_directory_is_writable($directory); if (!$writable && ($options & FILE_MODIFY_PERMISSIONS)) { return drupal_chmod($directory); } @@ -2112,6 +2112,25 @@ function file_get_mimetype($uri, $mapping = NULL) { } /** + * Determines if a directory is writable by the web server. + * + * In order to be able to write files within the directory, the directory + * itself must be writable, and it must also have the executable bit set. This + * helper function checks both at the same time. + * + * @param $uri + * A URI or pathname pointing to the directory that will be checked. + * + * @return + * TRUE if the directory is writable and executable; FALSE otherwise. + */ +function file_directory_is_writable($uri) { + // By converting the URI to a normal path using drupal_realpath(), we can + // correctly handle both stream wrappers and normal paths. + return is_writable(drupal_realpath($uri)) && drupal_is_executable($uri); +} + +/** * Sets the permissions on a file or directory. * * This function will use the 'file_chmod_directory' and 'file_chmod_file' @@ -2301,6 +2320,27 @@ function drupal_basename($uri, $suffix = NULL) { } /** + * Determines if a file or directory is executable. + * + * PHP's is_executable() does not fully support stream wrappers, so this + * function fills that gap. + * + * @param $uri + * A URI or pathname pointing to the file or directory that will be checked. + * + * @return + * TRUE if the file or directory is executable; FALSE otherwise. + * + * @see is_executable() + * @ingroup php_wrappers + */ +function drupal_is_executable($uri) { + // By converting the URI to a normal path using drupal_realpath(), we can + // correctly handle both stream wrappers and normal paths. + return is_executable(drupal_realpath($uri)); +} + +/** * Creates a directory using Drupal's default mode. * * PHP's mkdir() does not respect Drupal's default permissions mode. If a mode @@ -2438,7 +2478,7 @@ function file_directory_temp() { } foreach ($directories as $directory) { - if (is_dir($directory) && is_writable($directory)) { + if (is_dir($directory) && file_directory_is_writable($directory)) { $temporary_directory = $directory; break; } diff --git a/includes/install.core.inc b/includes/install.core.inc index ec3a853..4083f6b 100644 --- a/includes/install.core.inc +++ b/includes/install.core.inc @@ -1590,7 +1590,7 @@ function install_check_requirements($install_state) { // Otherwise, if settings.php does not exist yet, we can try to copy // default.settings.php to create it. elseif (!$exists) { - $copied = drupal_verify_install_file($conf_path, FILE_EXIST|FILE_WRITABLE, 'dir') && @copy($default_settings_file, $settings_file); + $copied = drupal_verify_install_file($conf_path, FILE_EXIST|FILE_WRITABLE|FILE_EXECUTABLE, 'dir') && @copy($default_settings_file, $settings_file); if ($copied) { // If the new settings file has the same owner as default.settings.php, // this means default.settings.php is owned by the webserver user. diff --git a/includes/install.inc b/includes/install.inc index 6411f8f..afd22f7 100644 --- a/includes/install.inc +++ b/includes/install.inc @@ -852,7 +852,7 @@ function drupal_verify_install_file($file, $mask = NULL, $type = 'file') { } break; case FILE_EXECUTABLE: - if (!is_executable($file) && !drupal_install_fix_file($file, $mask)) { + if (!drupal_is_executable($file) && !drupal_install_fix_file($file, $mask)) { $return = FALSE; } break; @@ -867,7 +867,7 @@ function drupal_verify_install_file($file, $mask = NULL, $type = 'file') { } break; case FILE_NOT_EXECUTABLE: - if (is_executable($file) && !drupal_install_fix_file($file, $mask)) { + if (drupal_is_executable($file) && !drupal_install_fix_file($file, $mask)) { $return = FALSE; } break; @@ -965,7 +965,7 @@ function drupal_install_fix_file($file, $mask, $message = TRUE) { } break; case FILE_EXECUTABLE: - if (!is_executable($file)) { + if (!drupal_is_executable($file)) { $mod |= 0111; } break; @@ -980,7 +980,7 @@ function drupal_install_fix_file($file, $mask, $message = TRUE) { } break; case FILE_NOT_EXECUTABLE: - if (is_executable($file)) { + if (drupal_is_executable($file)) { $mod &= ~0111; } break; diff --git a/includes/updater.inc b/includes/updater.inc index d4f99e9..4b03a26 100644 --- a/includes/updater.inc +++ b/includes/updater.inc @@ -351,7 +351,7 @@ class Updater { * If the chmod should be applied recursively. */ public function makeWorldReadable(&$filetransfer, $path, $recursive = TRUE) { - if (!is_executable($path)) { + if (!drupal_is_executable($path)) { // Set it to read + execute. $new_perms = substr(sprintf('%o', fileperms($path)), -4, -1) . "5"; $filetransfer->chmod($path, intval($new_perms, 8), $recursive); diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index fde0c28..b0b6351 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -1692,7 +1692,7 @@ function system_performance_settings() { ); $directory = 'public://'; - $is_writable = is_dir($directory) && is_writable($directory); + $is_writable = is_dir($directory) && file_directory_is_writable($directory); $disabled = !$is_writable; $disabled_message = ''; if (!$is_writable) { diff --git a/modules/system/system.install b/modules/system/system.install index 0b4e1fa..c655851 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -331,7 +331,7 @@ function system_requirements($phase) { if ($phase == 'install') { file_prepare_directory($directory, FILE_CREATE_DIRECTORY); } - $is_writable = is_writable($directory); + $is_writable = file_directory_is_writable($directory); $is_directory = is_dir($directory); if (!$is_writable || !$is_directory) { $description = ''; diff --git a/modules/system/system.module b/modules/system/system.module index 072850e..d36393f 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -2163,7 +2163,7 @@ function system_check_directory($form_element) { watchdog('file system', 'The directory %directory does not exist and could not be created.', array('%directory' => $directory), WATCHDOG_ERROR); } - if (is_dir($directory) && !is_writable($directory) && !drupal_chmod($directory)) { + if (is_dir($directory) && !file_directory_is_writable($directory) && !drupal_chmod($directory)) { // If the directory is not writable and cannot be made so. form_set_error($form_element['#parents'][0], t('The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory))); watchdog('file system', 'The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory), WATCHDOG_ERROR); diff --git a/modules/user/user.test b/modules/user/user.test index b5b64d6..7664d3b 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -877,7 +877,7 @@ class UserPictureTestCase extends DrupalWebTestCase { $picture_path = $file_dir . $picture_dir; $pic_check = file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY); - $this->_directory_test = is_writable($picture_path); + $this->_directory_test = file_directory_is_writable($picture_path); $this->assertTrue($this->_directory_test, "The directory $picture_path doesn't exist or is not writable. Further tests won't be made."); }