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) {
* 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
* (FILE_MODIFY_PERMISSIONS).
* @param int $mode
* Octal value for the permissions. Consult PHP chmod() documentation for
* more information.
*
* @return
* TRUE if the directory exists (or was created) and is writable. FALSE
* 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))) {
// Only trim if we're not dealing with a stream.
$directory = rtrim($directory, '/\\');
......@@ -498,14 +501,14 @@ function file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS)
// Let mkdir() recursively create directories and use the default directory
// permissions.
if ($options & FILE_CREATE_DIRECTORY) {
return @drupal_mkdir($directory, NULL, TRUE);
return @drupal_mkdir($directory, $mode, TRUE);
}
return FALSE;
}
// The directory exists, so check to see if it is writable.
$writable = is_writable($directory);
if (!$writable && ($options & FILE_MODIFY_PERMISSIONS)) {
return drupal_chmod($directory);
return drupal_chmod($directory, $mode);
}
return $writable;
......@@ -1258,8 +1261,8 @@ function file_get_mimetype($uri, $mapping = NULL) {
*
* @param $uri
* A string containing a URI file, or directory path.
* @param $mode
* Integer value for the permissions. Consult PHP chmod() documentation for
* @param int $mode
* Octal value for the permissions. Consult PHP chmod() documentation for
* more information.
*
* @return bool
......
......@@ -182,6 +182,8 @@ function install_state_defaults() {
// Whether or not this installation is interactive. By default this will
// be set to FALSE if settings are passed in to install_drupal().
'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
// or by the settings passed in to install_drupal(). This is primarily
// used to store 'profile' (the name of the chosen installation profile)
......@@ -1266,7 +1268,7 @@ function install_settings_form_submit($form, &$form_state) {
drupal_rewrite_settings($settings);
// 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
// storage override that the installer is using.
......@@ -2092,9 +2094,9 @@ function install_check_translations($install_state) {
$online = FALSE;
// 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.
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.
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
/**
* 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 update_prepare_d8_bootstrap()
*/
function drupal_install_config_directories() {
function drupal_install_config_directories($mode = NULL) {
global $config_directories;
// Add a randomized config directory name to settings.php, unless it was
......@@ -473,7 +477,7 @@ function drupal_install_config_directories() {
// public files directory, which has already been verified to be writable
// itself. But if it somehow fails anyway, the installation cannot proceed.
// 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(
'%directory' => config_get_config_directory($config_type),
'@handbook_url' => 'http://drupal.org/server-permissions',
......@@ -539,10 +543,14 @@ function install_verify_config_directory($type) {
* Type of config directory to return. Drupal core provides 'active' and
* 'staging'.
*
* @param int $mode
* Octal value for the permissions. Consult PHP chmod() documentation for
* more information.
*
* @return bool
* 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.
global $config_directories;
if (!isset($config_directories[$type])) {
......@@ -552,7 +560,7 @@ function install_ensure_config_directory($type) {
// directories that the installer creates.
else {
$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 @@
function image_install() {
// Create the styles directory and ensure it's writable.
$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) {
continue;
}
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_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