Commit d48480f3 authored by webchick's avatar webchick

Issue #2099467 by moshe weitzman, chx: Let non-interactive installers...

Issue #2099467 by moshe weitzman, chx: Let non-interactive installers determine mode of files directory and its subdirectories.
parent 50a7f295
...@@ -482,12 +482,15 @@ function file_create_url($uri) { ...@@ -482,12 +482,15 @@ function file_create_url($uri) {
* A bitmask to indicate if the directory should be created if it does * A bitmask to indicate if the directory should be created if it does
* not exist (FILE_CREATE_DIRECTORY) or made writable if it is read-only * not exist (FILE_CREATE_DIRECTORY) or made writable if it is read-only
* (FILE_MODIFY_PERMISSIONS). * (FILE_MODIFY_PERMISSIONS).
* @param int $mode
* Octal value for the permissions. Consult PHP chmod() documentation for
* more information.
* *
* @return * @return
* TRUE if the directory exists (or was created) and is writable. FALSE * TRUE if the directory exists (or was created) and is writable. FALSE
* otherwise. * otherwise.
*/ */
function file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS) { function file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS, $mode = NULL) {
if (!file_stream_wrapper_valid_scheme(file_uri_scheme($directory))) { if (!file_stream_wrapper_valid_scheme(file_uri_scheme($directory))) {
// Only trim if we're not dealing with a stream. // Only trim if we're not dealing with a stream.
$directory = rtrim($directory, '/\\'); $directory = rtrim($directory, '/\\');
...@@ -498,14 +501,14 @@ function file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS) ...@@ -498,14 +501,14 @@ function file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS)
// Let mkdir() recursively create directories and use the default directory // Let mkdir() recursively create directories and use the default directory
// permissions. // permissions.
if ($options & FILE_CREATE_DIRECTORY) { if ($options & FILE_CREATE_DIRECTORY) {
return @drupal_mkdir($directory, NULL, TRUE); return @drupal_mkdir($directory, $mode, TRUE);
} }
return FALSE; return FALSE;
} }
// The directory exists, so check to see if it is writable. // The directory exists, so check to see if it is writable.
$writable = is_writable($directory); $writable = is_writable($directory);
if (!$writable && ($options & FILE_MODIFY_PERMISSIONS)) { if (!$writable && ($options & FILE_MODIFY_PERMISSIONS)) {
return drupal_chmod($directory); return drupal_chmod($directory, $mode);
} }
return $writable; return $writable;
...@@ -1258,8 +1261,8 @@ function file_get_mimetype($uri, $mapping = NULL) { ...@@ -1258,8 +1261,8 @@ function file_get_mimetype($uri, $mapping = NULL) {
* *
* @param $uri * @param $uri
* A string containing a URI file, or directory path. * A string containing a URI file, or directory path.
* @param $mode * @param int $mode
* Integer value for the permissions. Consult PHP chmod() documentation for * Octal value for the permissions. Consult PHP chmod() documentation for
* more information. * more information.
* *
* @return bool * @return bool
......
...@@ -182,6 +182,8 @@ function install_state_defaults() { ...@@ -182,6 +182,8 @@ function install_state_defaults() {
// Whether or not this installation is interactive. By default this will // Whether or not this installation is interactive. By default this will
// be set to FALSE if settings are passed in to install_drupal(). // be set to FALSE if settings are passed in to install_drupal().
'interactive' => TRUE, 'interactive' => TRUE,
// The mode for directories that are created during install.
'mode' => NULL,
// An array of parameters for the installation, pre-populated by the URL // An array of parameters for the installation, pre-populated by the URL
// or by the settings passed in to install_drupal(). This is primarily // or by the settings passed in to install_drupal(). This is primarily
// used to store 'profile' (the name of the chosen installation profile) // used to store 'profile' (the name of the chosen installation profile)
...@@ -1266,7 +1268,7 @@ function install_settings_form_submit($form, &$form_state) { ...@@ -1266,7 +1268,7 @@ function install_settings_form_submit($form, &$form_state) {
drupal_rewrite_settings($settings); drupal_rewrite_settings($settings);
// Add the config directories to settings.php. // Add the config directories to settings.php.
drupal_install_config_directories(); drupal_install_config_directories($install_state['mode']);
// The container is about to be rebuilt so we need to unset the keyvalue // The container is about to be rebuilt so we need to unset the keyvalue
// storage override that the installer is using. // storage override that the installer is using.
...@@ -2092,9 +2094,9 @@ function install_check_translations($install_state) { ...@@ -2092,9 +2094,9 @@ function install_check_translations($install_state) {
$online = FALSE; $online = FALSE;
// First attempt to create or make writable the files directory. // First attempt to create or make writable the files directory.
file_prepare_directory($files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); file_prepare_directory($files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, $install_state['mode']);
// Then, attempt to create or make writable the translations directory. // Then, attempt to create or make writable the translations directory.
file_prepare_directory($translations_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); file_prepare_directory($translations_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, $install_state['mode']);
// Get values so the requirements errors can be specific. // Get values so the requirements errors can be specific.
if (drupal_verify_install_file($translations_directory, FILE_EXIST|FILE_WRITABLE, 'dir')) { if (drupal_verify_install_file($translations_directory, FILE_EXIST|FILE_WRITABLE, 'dir')) {
......
...@@ -437,10 +437,14 @@ function _drupal_rewrite_settings_dump_one(\stdClass $variable, $prefix = '', $s ...@@ -437,10 +437,14 @@ function _drupal_rewrite_settings_dump_one(\stdClass $variable, $prefix = '', $s
/** /**
* Creates the config directory and ensures it is operational. * Creates the config directory and ensures it is operational.
* *
* @param int $mode
* Octal value for the permissions. Consult PHP chmod() documentation for
* more information.
*
* @see install_settings_form_submit() * @see install_settings_form_submit()
* @see update_prepare_d8_bootstrap() * @see update_prepare_d8_bootstrap()
*/ */
function drupal_install_config_directories() { function drupal_install_config_directories($mode = NULL) {
global $config_directories; global $config_directories;
// Add a randomized config directory name to settings.php, unless it was // Add a randomized config directory name to settings.php, unless it was
...@@ -473,7 +477,7 @@ function drupal_install_config_directories() { ...@@ -473,7 +477,7 @@ function drupal_install_config_directories() {
// public files directory, which has already been verified to be writable // public files directory, which has already been verified to be writable
// itself. But if it somehow fails anyway, the installation cannot proceed. // itself. But if it somehow fails anyway, the installation cannot proceed.
// Bail out using a similar error message as in system_requirements(). // Bail out using a similar error message as in system_requirements().
if (!install_ensure_config_directory($config_type)) { if (!install_ensure_config_directory($config_type, $mode)) {
throw new Exception(t('The directory %directory could not be created or could not be made writable. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see the <a href="@handbook_url">online handbook</a>.', array( throw new Exception(t('The directory %directory could not be created or could not be made writable. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see the <a href="@handbook_url">online handbook</a>.', array(
'%directory' => config_get_config_directory($config_type), '%directory' => config_get_config_directory($config_type),
'@handbook_url' => 'http://drupal.org/server-permissions', '@handbook_url' => 'http://drupal.org/server-permissions',
...@@ -539,10 +543,14 @@ function install_verify_config_directory($type) { ...@@ -539,10 +543,14 @@ function install_verify_config_directory($type) {
* Type of config directory to return. Drupal core provides 'active' and * Type of config directory to return. Drupal core provides 'active' and
* 'staging'. * 'staging'.
* *
* @param int $mode
* Octal value for the permissions. Consult PHP chmod() documentation for
* more information.
*
* @return bool * @return bool
* TRUE if the config directory exists and is writable. * TRUE if the config directory exists and is writable.
*/ */
function install_ensure_config_directory($type) { function install_ensure_config_directory($type, $mode = NULL) {
// The config directory must be defined in settings.php. // The config directory must be defined in settings.php.
global $config_directories; global $config_directories;
if (!isset($config_directories[$type])) { if (!isset($config_directories[$type])) {
...@@ -552,7 +560,7 @@ function install_ensure_config_directory($type) { ...@@ -552,7 +560,7 @@ function install_ensure_config_directory($type) {
// directories that the installer creates. // directories that the installer creates.
else { else {
$config_directory = config_get_config_directory($type); $config_directory = config_get_config_directory($type);
return file_prepare_directory($config_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); return file_prepare_directory($config_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, $mode);
} }
} }
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
function image_install() { function image_install() {
// Create the styles directory and ensure it's writable. // Create the styles directory and ensure it's writable.
$directory = file_default_scheme() . '://styles'; $directory = file_default_scheme() . '://styles';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); $mode = isset($GLOBALS['install_state']['mode']) ? $GLOBALS['install_state']['mode'] : NULL;
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, $mode);
} }
/** /**
......
...@@ -371,7 +371,8 @@ function system_requirements($phase) { ...@@ -371,7 +371,8 @@ function system_requirements($phase) {
continue; continue;
} }
if ($phase == 'install') { if ($phase == 'install') {
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); $mode = isset($GLOBALS['install_state']['mode']) ? $GLOBALS['install_state']['mode'] : NULL;
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, $mode);
} }
$is_writable = is_writable($directory); $is_writable = is_writable($directory);
$is_directory = is_dir($directory); $is_directory = is_dir($directory);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment