Commit fb300d1f authored by Dries's avatar Dries

- Patch #895308 by Damien Tournoud: remove file_directory_path().

parent d62224dc
......@@ -4587,7 +4587,7 @@ function _drupal_bootstrap_full() {
// Running inside the simpletest child site, log fatal errors to test
// specific file directory.
ini_set('log_errors', 1);
ini_set('error_log', file_directory_path() . '/error.log');
ini_set('error_log', 'public://error.log');
}
// Initialize $_GET['q'] prior to invoking hook_init().
......
......@@ -222,6 +222,16 @@ function file_uri_target($uri) {
return count($data) == 2 ? trim($data[1], '\/') : FALSE;
}
/**
* Get the default file stream implementation.
*
* @return
* 'public', 'private' or any other file scheme defined as the default.
*/
function file_default_scheme() {
return variable_get('file_default_scheme', 'public');
}
/**
* Normalizes a URI by making it syntactically correct.
*
......@@ -317,11 +327,9 @@ function file_stream_wrapper_get_instance_by_scheme($scheme) {
* @see http://drupal.org/node/515192
*
* There are two kinds of local files:
* - "created files", i.e. those in the files directory (which is stored in
* the file_directory_path variable and can be retrieved using
* file_directory_path()). These are files that have either been uploaded by
* users or were generated automatically (for example through CSS
* aggregation).
* - "managed files", i.e. those stored by a Drupal-compatible stream wrapper.
* These are files that have either been uploaded by users or were generated
* automatically (for example through CSS aggregation).
* - "shipped files", i.e. those outside of the files directory, which ship as
* part of Drupal core or contributed modules or themes.
*
......@@ -829,7 +837,7 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST
* Given a relative path, construct a URI into Drupal's default files location.
*/
function file_build_uri($path) {
$uri = variable_get('file_default_scheme', 'public') . '://' . $path;
$uri = file_default_scheme() . '://' . $path;
return file_stream_wrapper_uri_normalize($uri);
}
......@@ -1888,33 +1896,6 @@ function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
return $files;
}
/**
* Determines the local directory path of a given wrapper.
*
* This function will return the directory path of a stream wrapper. A stream
* is referenced as: "scheme://target". For example, a scheme of "public"
* might return "sites/default/files" or "temporary" might return "/tmp".
*
* @param $scheme
* A string representing the scheme of a stream. The default wrapper is
* is assumed if this is not provided.
*
* @return
* A string containing the directory path of a stream. FALSE is returned if
* the scheme is invalid or a wrapper could not be instantiated.
*/
function file_directory_path($scheme = NULL) {
if (empty($scheme)) {
$scheme = variable_get('file_default_scheme', 'public');
}
if ($wrapper = file_stream_wrapper_get_instance_by_scheme($scheme)) {
return $wrapper->getDirectoryPath();
}
else {
return FALSE;
}
}
/**
* Determine the maximum file upload size by querying the PHP settings.
*
......@@ -2269,9 +2250,9 @@ function file_directory_temp() {
}
}
// if a directory has been found, use it, otherwise default to 'files/tmp' or 'files\\tmp'.
if (empty($temporary_directory)) {
$temporary_directory = file_directory_path() . $path_delimiter . 'tmp';
// If no directory has been found default to 'files/tmp' or 'files\\tmp'.
$temporary_directory = variable_get('file_public_path', conf_path() . '/files') . $path_delimiter . 'tmp';
}
// Save the path of the discovered directory.
variable_set('file_directory_temp', $temporary_directory);
......
......@@ -368,7 +368,7 @@ public function makeBackup(&$filetransfer, $from, $to) {
* Return the full path to a directory where backups should be written.
*/
public function getBackupDir() {
return file_directory_path('temporary');
return file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath();
}
/**
......
......@@ -193,15 +193,7 @@ function _file_generic_settings_extensions($element, &$form_state) {
function _file_generic_settings_file_directory_validate($element, &$form_state) {
// Strip slashes from the beginning and end of $widget['file_directory'].
$value = trim($element['#value'], '\\/');
// Do not allow the file path to be the same as the file_directory_path().
// This causes all sorts of problems with things like file_create_url().
if (strpos($value, file_directory_path()) === 0) {
form_error($element, t('The file directory (@file_directory) cannot start with the system files directory (@files_directory), as this may cause conflicts when building file URLs.', array('@file_directory' => $form_state['values']['file_directory'], '@files_directory' => file_directory_path())));
}
else {
form_set_value($element, $value, $form_state);
}
form_set_value($element, $value, $form_state);
}
/**
......
......@@ -11,8 +11,8 @@
*/
function image_install() {
// Create the styles directory and ensure it's writable.
$path = file_directory_path() . '/styles';
file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
$directory = file_default_scheme() . '://styles';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
/**
......@@ -20,8 +20,7 @@ function image_install() {
*/
function image_uninstall() {
// Remove the styles directory and generated images.
$path = file_directory_path() . '/styles';
file_unmanaged_delete_recursive($path);
file_unmanaged_delete_recursive(file_default_scheme() . '://styles');
}
/**
......
......@@ -75,11 +75,12 @@ function image_menu() {
// If clean URLs are disabled, image derivatives will always be served
// through the menu system.
// If clean URLs are enabled and the image derivative already exists,
// PHP will be bypassed.
$items[file_directory_path('public') . '/styles/%image_style'] = array(
// PHP will be bypassed.
$directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath();
$items[$directory_path . '/styles/%image_style'] = array(
'title' => 'Generate image style',
'page callback' => 'image_style_deliver',
'page arguments' => array(count(explode('/', file_directory_path())) + 1),
'page arguments' => array(count(explode('/', $directory_path)) + 1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
......@@ -763,7 +764,7 @@ function image_style_create_derivative($style, $source, $destination) {
* An image style array.
*/
function image_style_flush($style) {
$style_directory = drupal_realpath(variable_get('file_default_scheme', 'public') . '://styles/' . $style['name']);
$style_directory = drupal_realpath(file_default_scheme() . '://styles/' . $style['name']);
if (is_dir($style_directory)) {
file_unmanaged_delete_recursive($style_directory);
}
......@@ -808,7 +809,7 @@ function image_style_url($style_name, $path) {
}
else {
$destination = image_style_path($style_name, $path);
$url = url(file_directory_path($scheme) . '/' . file_uri_target($destination), array('absolute' => TRUE));
$url = url(file_stream_wrapper_get_instance_by_scheme($scheme)->getDirectoryPath() . '/' . file_uri_target($destination), array('absolute' => TRUE));
}
return $url;
}
......@@ -834,7 +835,7 @@ function image_style_path($style_name, $uri) {
}
else {
$path = $uri;
$scheme = variable_get('file_default_scheme', 'public');
$scheme = file_default_scheme();
}
return $scheme . '://styles/' . $style_name . '/' . $scheme . '/' . $path;
}
......
......@@ -334,8 +334,7 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
* Count the number of images currently create for a style.
*/
function getImageCount($style) {
$directory = file_directory_path() . '/styles/' . $style['name'];
return count(file_scan_directory($directory, '/.*/'));
return count(file_scan_directory('public://styles/' . $style['name'], '/.*/'));
}
/**
......@@ -482,7 +481,7 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
$this->drupalPost('admin/config/media/image-styles/delete/' . $style_name, array(), t('Delete'));
// Confirm the style directory has been removed.
$directory = file_directory_path() . '/styles/' . $style_name;
$directory = file_default_scheme() . '://styles/' . $style_name;
$this->assertFalse(is_dir($directory), t('Image style %style directory removed on style deletion.', array('%style' => $style['name'])));
drupal_static_reset('image_styles');
......
......@@ -758,7 +758,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase {
* Additional options to pass to the translation import form.
*/
function importPoFile($contents, array $options = array()) {
$name = tempnam(file_directory_path('temporary'), "po_") . '.po';
$name = tempnam('temporary://', "po_") . '.po';
file_put_contents($name, $contents);
$options['files[file]'] = $name;
$this->drupalPost('admin/config/regional/translate/import', $options, t('Import'));
......@@ -905,7 +905,7 @@ class LocaleExportFunctionalTest extends DrupalWebTestCase {
function testExportTranslation() {
// First import some known translations.
// This will also automatically enable the 'fr' language.
$name = tempnam(file_directory_path('temporary'), "po_") . '.po';
$name = tempnam('temporary://', "po_") . '.po';
file_put_contents($name, $this->getPoFile());
$this->drupalPost('admin/config/regional/translate/import', array(
'langcode' => 'fr',
......
......@@ -416,7 +416,7 @@ protected function error($message = '', $group = 'Other', array $caller = NULL)
*/
public function run() {
// Initialize verbose debugging.
simpletest_verbose(NULL, file_directory_path(), get_class($this));
simpletest_verbose(NULL, variable_get('file_public_path', conf_path() . '/files'), get_class($this));
// HTTP auth settings (<username>:<password>) for the simpletest browser
// when sending requests to the test site.
......@@ -568,7 +568,7 @@ protected function setUp() {
global $conf;
// Store necessary current values before switching to the test environment.
$this->originalFileDirectory = file_directory_path();
$this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
spl_autoload_register('db_autoload');
......@@ -903,9 +903,8 @@ protected function drupalGetTestFiles($type, $size = NULL) {
// Copy other test files from simpletest.
$original = drupal_get_path('module', 'simpletest') . '/files';
$files = file_scan_directory($original, '/(html|image|javascript|php|sql)-.*/');
$destination_path = file_directory_path('public');
foreach ($files as $file) {
file_unmanaged_copy($file->uri, $destination_path);
file_unmanaged_copy($file->uri, variable_get('file_public_path', conf_path() . '/files'));
}
$this->generatedTestFiles = TRUE;
......@@ -914,7 +913,7 @@ protected function drupalGetTestFiles($type, $size = NULL) {
$files = array();
// Make sure type is valid.
if (in_array($type, array('binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'))) {
$files = file_scan_directory(file_directory_path('public'), '/' . $type . '\-.*/');
$files = file_scan_directory(variable_get('file_public_path', conf_path() . '/files'), '/' . $type . '\-.*/');
// If size is set then remove any files that are not of that size.
if ($size !== NULL) {
......@@ -1152,7 +1151,7 @@ protected function setUp() {
// Store necessary current values before switching to prefixed database.
$this->originalLanguage = $language;
$this->originalLanguageDefault = variable_get('language_default');
$this->originalFileDirectory = file_directory_path();
$this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
$this->originalProfile = drupal_get_profile();
$clean_url_original = variable_get('clean_url', 0);
......
......@@ -20,7 +20,7 @@ function simpletest_uninstall() {
variable_del('simpletest_verbose');
// Remove generated files.
$path = file_directory_path() . '/simpletest';
$path = 'public://simpletest';
$files = file_scan_directory($path, '/.*/');
foreach ($files as $file) {
file_unmanaged_delete($file->uri);
......
......@@ -131,7 +131,7 @@ function simpletest_run_tests($test_list, $reporter = 'drupal') {
->execute();
// Clear out the previous verbose files.
file_unmanaged_delete_recursive(file_directory_path() . '/simpletest/verbose');
file_unmanaged_delete_recursive('public://simpletest/verbose');
// Get the info for the first test being run.
$first_test = array_shift($test_list);
......@@ -406,7 +406,7 @@ function simpletest_generate_file($filename, $width, $lines, $type = 'binary-tex
$text = wordwrap($text, $width - 1, "\n", TRUE) . "\n"; // Add \n for symetrical file.
// Create filename.
file_put_contents(file_directory_path() . '/' . $filename . '.txt', $text);
file_put_contents('public://' . $filename . '.txt', $text);
return $filename;
}
......
......@@ -433,11 +433,13 @@ class SimpleTestFolderTestCase extends DrupalWebTestCase {
);
}
function setUp() {
return parent::setUp('image');
}
function testFolderSetup() {
if (module_exists('image')) {
$path = file_directory_path() . '/styles';
$this->assertTrue(file_prepare_directory($path, FALSE), "Directory created.");
}
$directory = file_default_scheme() . '://styles';
$this->assertTrue(file_prepare_directory($directory, FALSE), "Directory created.");
}
}
......
This diff is collapsed.
......@@ -36,7 +36,7 @@ class FileTranferTest extends DrupalWebTestCase {
}
function _buildFakeModule() {
$location = file_directory_path('temporary') . '/fake';
$location = 'temporary://fake';
if (is_dir($location)) {
$ret = 0;
$output = array();
......@@ -80,7 +80,7 @@ class FileTranferTest extends DrupalWebTestCase {
$gotit = TRUE;
try {
$this->testConnection->copyDirectory($source, DRUPAL_ROOT . '/'. file_directory_path());
$this->testConnection->copyDirectory($source, DRUPAL_ROOT . '/'. variable_get('file_public_path', conf_path() . '/files'));
}
catch (FileTransferException $e) {
$gotit = FALSE;
......
......@@ -444,7 +444,7 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
$correct_colors = $this->colorsAreEqual($color, $corner);
}
$directory = file_directory_path() . '/imagetests';
$directory = file_default_scheme() . '://imagetests';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
image_save($image, $directory . '/' . $op . '.' . $image->info['extension']);
......
......@@ -64,7 +64,7 @@ class RegistryParseFilesTestCase extends DrupalWebTestCase {
foreach ($this->fileTypes as $fileType) {
$chrs = hash('sha256', microtime() . mt_rand());
$this->$fileType = new stdClass();
$this->$fileType->fileName = file_directory_path() . '/registry_test_' . substr($chrs, 0, 16);
$this->$fileType->fileName = 'public://registry_test_' . substr($chrs, 0, 16);
$this->$fileType->className = 'registry_test_class' . substr($chrs, 16, 16);
$this->$fileType->interfaceName = 'registry_test_interface' . substr($chrs, 32, 16);
$this->$fileType->contents = $this->getFileContents($fileType);
......
......@@ -191,7 +191,7 @@ class SessionTestCase extends DrupalWebTestCase {
$this->loggedInUser = FALSE;
// Change cookie file for user.
$this->cookieFile = file_directory_path('temporary') . '/cookie.' . $uid . '.txt';
$this->cookieFile = file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath() . '/cookie.' . $uid . '.txt';
$this->additionalCurlOptions[CURLOPT_COOKIEFILE] = $this->cookieFile;
$this->additionalCurlOptions[CURLOPT_COOKIESESSION] = TRUE;
$this->drupalGet('session-test/get');
......
......@@ -58,7 +58,7 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
// Store necessary current values before switching to prefixed database.
$this->originalLanguage = $language;
$this->originalLanguageDefault = variable_get('language_default');
$this->originalFileDirectory = file_directory_path();
$this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
$this->originalProfile = drupal_get_profile();
$clean_url_original = variable_get('clean_url', 0);
......
......@@ -1805,7 +1805,7 @@ function system_file_system_settings() {
$form['file_public_path'] = array(
'#type' => 'textfield',
'#title' => t('Public file system path'),
'#default_value' => variable_get('file_public_path', file_directory_path()),
'#default_value' => variable_get('file_public_path', conf_path() . '/files'),
'#maxlength' => 255,
'#description' => t('A local file system path where public files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web.'),
'#after_build' => array('system_check_directory'),
......@@ -1814,7 +1814,7 @@ function system_file_system_settings() {
$form['file_private_path'] = array(
'#type' => 'textfield',
'#title' => t('Private file system path'),
'#default_value' => variable_get('file_private_path', file_directory_path('private')),
'#default_value' => variable_get('file_private_path', ''),
'#maxlength' => 255,
'#description' => t('A local file system path where private files will be stored. This directory must exist and be writable by Drupal. This directory should not be accessible over the web.'),
'#after_build' => array('system_check_directory'),
......@@ -1823,7 +1823,7 @@ function system_file_system_settings() {
$form['file_temporary_path'] = array(
'#type' => 'textfield',
'#title' => t('Temporary directory'),
'#default_value' => variable_get('file_temporary_path', file_directory_path('temporary')),
'#default_value' => variable_get('file_temporary_path', file_directory_temp()),
'#maxlength' => 255,
'#description' => t('A local file system path where temporary files will be stored. This directory should not be accessible over the web.'),
'#after_build' => array('system_check_directory'),
......
......@@ -323,7 +323,7 @@ function system_requirements($phase) {
}
}
else {
if (variable_get('file_default_scheme', 'public') == 'public') {
if (file_default_scheme() == 'public') {
$requirements['file system']['value'] = $t('Writable (<em>public</em> download method)');
}
else {
......@@ -2726,7 +2726,7 @@ function system_update_7060(&$sandbox) {
'settings' => array(
'display_field' => 1,
'display_default' => variable_get('upload_list_default', 1),
'uri_scheme' => variable_get('file_default_scheme', 'public'),
'uri_scheme' => file_default_scheme(),
'default_file' => 0,
),
);
......@@ -2830,7 +2830,7 @@ function system_update_7060(&$sandbox) {
}
$basename = variable_get('file_directory_path', conf_path() . '/files');
$scheme = variable_get('file_default_scheme', 'public') . '://';
$scheme = file_default_scheme() . '://';
foreach ($node_revisions as $vid => $revision) {
// We will convert filepaths to uri using the default scheme
// and stripping off the existing file directory path.
......
......@@ -341,7 +341,7 @@ function user_admin_settings() {
);
// If picture support is enabled, check whether the picture directory exists.
if (variable_get('user_pictures', 0)) {
$picture_path = variable_get('file_default_scheme', 'public') . '://' . variable_get('user_picture_path', 'pictures');
$picture_path = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures');
if (!file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY)) {
form_set_error('user_picture_path', t('The directory %directory does not exist or is not writable.', array('%directory' => $picture_path)));
watchdog('file system', 'The directory %directory does not exist or is not writable.', array('%directory' => $picture_path), WATCHDOG_ERROR);
......@@ -369,7 +369,7 @@ function user_admin_settings() {
'#default_value' => variable_get('user_picture_path', 'pictures'),
'#size' => 30,
'#maxlength' => 255,
'#description' => t('Subdirectory in the directory %dir where pictures will be stored.', array('%dir' => file_directory_path() . '/')),
'#description' => t('Subdirectory in the file upload directory where pictures will be stored.'),
);
$form['personalization']['pictures']['user_picture_default'] = array(
'#type' => 'textfield',
......
......@@ -433,7 +433,7 @@ function user_save($account, $edit = array(), $category = 'account') {
// make it permanent.
if (!$picture->status) {
$info = image_get_info($picture->uri);
$picture_directory = variable_get('file_default_scheme', 'public') . '://' . variable_get('user_picture_path', 'pictures');
$picture_directory = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures');
// Prepare the pictures directory.
file_prepare_directory($picture_directory, FILE_CREATE_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