diff --git a/core/includes/common.inc b/core/includes/common.inc index 037c5b0..7f589c3 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1244,7 +1244,7 @@ function archiver_get_extensions() { */ function archiver_get_archiver($file) { // Archivers can only work on local paths - $filepath = drupal_realpath($file); + $filepath = \Drupal::service('file_system')->realpath($file); if (!is_file($filepath)) { throw new Exception(t('Archivers can only operate on local files: %file not supported', array('%file' => $file))); } diff --git a/core/includes/file.inc b/core/includes/file.inc index 0dcd141..fca3f09 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -502,7 +502,7 @@ function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_E if (!file_exists($source)) { // @todo Replace drupal_set_message() calls with exceptions instead. drupal_set_message(t('The specified file %file could not be moved/copied because no file by that name exists. Please check that you supplied the correct filename.', array('%file' => $original_source)), 'error'); - if (($realpath = drupal_realpath($original_source)) !== FALSE) { + if (($realpath = \Drupal::service('file_system')->realpath($original_source)) !== FALSE) { $logger->notice('File %file (%realpath) could not be moved/copied because it does not exist.', array('%file' => $original_source, '%realpath' => $realpath)); } else { @@ -542,8 +542,8 @@ function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_E } // Assert that the source and destination filenames are not the same. - $real_source = drupal_realpath($source); - $real_destination = drupal_realpath($destination); + $real_source = \Drupal::service('file_system')->realpath($source); + $real_destination = \Drupal::service('file_system')->realpath($destination); if ($source == $destination || ($real_source !== FALSE) && ($real_source == $real_destination)) { drupal_set_message(t('The specified file %file was not moved/copied because it would overwrite itself.', array('%file' => $source)), 'error'); $logger->notice('File %file could not be moved/copied because it would overwrite itself.', array('%file' => $source)); diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index ceb9982..a83d885 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1358,7 +1358,7 @@ function install_download_translation(&$install_state) { */ function install_retrieve_file($uri, $destination) { $parsed_url = parse_url($uri); - if (is_dir(drupal_realpath($destination))) { + if (is_dir(\Drupal::service('file_system')->realpath($destination))) { // Prevent URIs with triple slashes when gluing parts together. $path = str_replace('///', '//', "$destination/") . drupal_basename($parsed_url['path']); } diff --git a/core/lib/Drupal/Core/FileTransfer/FileTransfer.php b/core/lib/Drupal/Core/FileTransfer/FileTransfer.php index dbe2559..21ab352 100644 --- a/core/lib/Drupal/Core/FileTransfer/FileTransfer.php +++ b/core/lib/Drupal/Core/FileTransfer/FileTransfer.php @@ -207,7 +207,7 @@ function __get($name) { */ protected final function checkPath($path) { $full_jail = $this->chroot . $this->jail; - $full_path = drupal_realpath(substr($this->chroot . $path, 0, strlen($full_jail))); + $full_path = \Drupal::service('file_system')->realpath(substr($this->chroot . $path, 0, strlen($full_jail))); $full_path = $this->fixRemotePath($full_path, FALSE); if ($full_jail !== $full_path) { throw new FileTransferException('@directory is outside of the @jail', NULL, array('@directory' => $path, '@jail' => $this->jail)); diff --git a/core/modules/color/color.module b/core/modules/color/color.module index 1dbc1da..b26eed6 100644 --- a/core/modules/color/color.module +++ b/core/modules/color/color.module @@ -635,7 +635,7 @@ function _color_render_images($theme, &$info, &$paths, $palette) { foreach ($info['slices'] as $file => $coord) { list($x, $y, $width, $height) = $coord; $base = drupal_basename($file); - $image = drupal_realpath($paths['target'] . $base); + $image = \Drupal::service('file_system')->realpath($paths['target'] . $base); // Cut out slice. if ($file == 'screenshot.png') { diff --git a/core/modules/color/tests/src/Functional/ColorTest.php b/core/modules/color/tests/src/Functional/ColorTest.php index dc44566..e9ccccd 100644 --- a/core/modules/color/tests/src/Functional/ColorTest.php +++ b/core/modules/color/tests/src/Functional/ColorTest.php @@ -141,7 +141,7 @@ function _testColor($theme, $test_values) { $stylesheets = \Drupal::state()->get('drupal_css_cache_files') ?: array(); $stylesheet_content = ''; foreach ($stylesheets as $uri) { - $stylesheet_content .= join("\n", file(drupal_realpath($uri))); + $stylesheet_content .= join("\n", file($this->container->get('file_system')->realpath($uri))); } $this->assertTrue(strpos($stylesheet_content, 'public://') === FALSE, 'Make sure the color paths have been translated to local paths. (' . $theme . ')'); $config->set('css.preprocess', 0); diff --git a/core/modules/comment/src/Tests/CommentPreviewTest.php b/core/modules/comment/src/Tests/CommentPreviewTest.php index 837a78a..4c3bd83 100644 --- a/core/modules/comment/src/Tests/CommentPreviewTest.php +++ b/core/modules/comment/src/Tests/CommentPreviewTest.php @@ -55,7 +55,7 @@ function testCommentPreview() { // Add a user picture. $image = current($this->drupalGetTestFiles('image')); - $user_edit['files[user_picture_0]'] = drupal_realpath($image->uri); + $user_edit['files[user_picture_0]'] = $this->container->get('file_system')->realpath($image->uri); $this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $user_edit, t('Save')); // As the web user, fill in the comment form and preview the comment. diff --git a/core/modules/config/src/Tests/ConfigImportUploadTest.php b/core/modules/config/src/Tests/ConfigImportUploadTest.php index 9836d77..3018cbd 100644 --- a/core/modules/config/src/Tests/ConfigImportUploadTest.php +++ b/core/modules/config/src/Tests/ConfigImportUploadTest.php @@ -42,7 +42,7 @@ function testImport() { // Attempt to upload a non-tar file. $text_file = current($this->drupalGetTestFiles('text')); - $edit = array('files[import_tarball]' => drupal_realpath($text_file->uri)); + $edit = array('files[import_tarball]' => $this->container->get('file_system')->realpath($text_file->uri)); $this->drupalPostForm('admin/config/development/configuration/full/import', $edit, t('Upload')); $this->assertText(t('Could not extract the contents of the tar file')); diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceFileUploadTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceFileUploadTest.php index 6aef0f8..a10bd40 100644 --- a/core/modules/field/src/Tests/EntityReference/EntityReferenceFileUploadTest.php +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceFileUploadTest.php @@ -115,7 +115,7 @@ public function testFileUpload() { $this->drupalLogin($user1); $test_file = current($this->drupalGetTestFiles('text')); - $edit['files[file_field_0]'] = drupal_realpath($test_file->uri); + $edit['files[file_field_0]'] = $this->container->get('file_system')->realpath($test_file->uri); $this->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Upload'); $this->assertResponse(200); $edit = array( diff --git a/core/modules/file/file.module b/core/modules/file/file.module index c63fff4..ff722cd 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -140,7 +140,7 @@ function file_load($fid, $reset = FALSE) { */ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) { if (!file_valid_uri($destination)) { - if (($realpath = drupal_realpath($source->getFileUri())) !== FALSE) { + if (($realpath = \Drupal::service('file_system')->realpath($source->getFileUri())) !== FALSE) { \Drupal::logger('file')->notice('File %file (%realpath) could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination)); } else { @@ -215,7 +215,7 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E */ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) { if (!file_valid_uri($destination)) { - if (($realpath = drupal_realpath($source->getFileUri())) !== FALSE) { + if (($realpath = \Drupal::service('file_system')->realpath($source->getFileUri())) !== FALSE) { \Drupal::logger('file')->notice('File %file (%realpath) could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination)); } else { diff --git a/core/modules/file/src/Tests/FileFieldDisplayTest.php b/core/modules/file/src/Tests/FileFieldDisplayTest.php index 142751a..5b0bff0 100644 --- a/core/modules/file/src/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/src/Tests/FileFieldDisplayTest.php @@ -88,7 +88,7 @@ function testNodeDisplay() { // Test that fields appear as expected after during the preview. // Add a second file. $name = 'files[' . $field_name . '_1][]'; - $edit[$name] = drupal_realpath($test_file->getFileUri()); + $edit[$name] = $this->container->get('file_system')->realpath($test_file->getFileUri()); // Uncheck the display checkboxes and go to the preview. $edit[$field_name . '[0][display]'] = FALSE; @@ -157,7 +157,7 @@ function testDescToggle() { $title = $this->randomString(); $edit = array( 'title[0][value]' => $title, - 'files[field_' . $field_name . '_0]' => drupal_realpath($file->uri), + 'files[field_' . $field_name . '_0]' => $this->container->get('file_system')->realpath($file->uri), ); $this->drupalPostForm('node/add/' . $type_name, $edit, t('Save and publish')); $node = $this->drupalGetNodeByTitle($title); diff --git a/core/modules/file/src/Tests/FileFieldTestBase.php b/core/modules/file/src/Tests/FileFieldTestBase.php index 307eb4d..004cbe2 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php @@ -248,7 +248,7 @@ function removeNodeFile($nid, $new_revision = TRUE) { */ function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) { $edit = array( - 'files[' . $field_name . '_0]' => drupal_realpath($file->getFileUri()), + 'files[' . $field_name . '_0]' => $this->container->get('file_system')->realpath($file->getFileUri()), 'revision' => (string) (int) $new_revision, ); diff --git a/core/modules/file/src/Tests/FileFieldWidgetTest.php b/core/modules/file/src/Tests/FileFieldWidgetTest.php index 414c86b..697eff4 100644 --- a/core/modules/file/src/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php @@ -160,7 +160,7 @@ function testMultiValuedWidget() { $this->drupalGet("node/add/$type_name"); foreach (array($field_name2, $field_name) as $each_field_name) { for ($delta = 0; $delta < 3; $delta++) { - $edit = array('files[' . $each_field_name . '_' . $delta . '][]' => drupal_realpath($test_file->getFileUri())); + $edit = array('files[' . $each_field_name . '_' . $delta . '][]' => $this->container->get('file_system')->realpath($test_file->getFileUri())); // If the Upload button doesn't exist, drupalPostForm() will automatically // fail with an assertion message. $this->drupalPostForm(NULL, $edit, t('Upload')); @@ -374,7 +374,7 @@ function testPrivateFileComment() { // Add a comment with a file. $text_file = $this->getTestFile('text'); $edit = array( - 'files[field_' . $name . '_' . 0 . ']' => drupal_realpath($text_file->getFileUri()), + 'files[field_' . $name . '_' . 0 . ']' => $this->container->get('file_system')->realpath($text_file->getFileUri()), 'comment_body[0][value]' => $comment_body = $this->randomMachineName(), ); $this->drupalPostForm('node/' . $node->id(), $edit, t('Save')); @@ -429,7 +429,7 @@ function testWidgetValidation() { $name = 'files[' . $field_name . '_0]'; // Upload file with incorrect extension, check for validation error. - $edit[$name] = drupal_realpath($test_file_image->getFileUri()); + $edit[$name] = $this->container->get('file_system')->realpath($test_file_image->getFileUri()); switch ($type) { case 'nojs': $this->drupalPostForm(NULL, $edit, t('Upload')); @@ -443,7 +443,7 @@ function testWidgetValidation() { $this->assertRaw($error_message, t('Validation error when file with wrong extension uploaded (JSMode=%type).', array('%type' => $type))); // Upload file with correct extension, check that error message is removed. - $edit[$name] = drupal_realpath($test_file_text->getFileUri()); + $edit[$name] = $this->container->get('file_system')->realpath($test_file_text->getFileUri()); switch ($type) { case 'nojs': $this->drupalPostForm(NULL, $edit, t('Upload')); diff --git a/core/modules/file/src/Tests/FileListingTest.php b/core/modules/file/src/Tests/FileListingTest.php index 708f138..65d517f 100644 --- a/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/src/Tests/FileListingTest.php @@ -91,7 +91,7 @@ function testFileListingPages() { $file = $this->getTestFile('image'); $edit = array( - 'files[file_0]' => drupal_realpath($file->getFileUri()), + 'files[file_0]' => $this->container->get('file_system')->realpath($file->getFileUri()), ); $this->drupalPostForm(NULL, $edit, t('Save')); $node = Node::load($node->id()); diff --git a/core/modules/file/src/Tests/FileManagedFileElementTest.php b/core/modules/file/src/Tests/FileManagedFileElementTest.php index 07102a0..6446926 100644 --- a/core/modules/file/src/Tests/FileManagedFileElementTest.php +++ b/core/modules/file/src/Tests/FileManagedFileElementTest.php @@ -36,7 +36,7 @@ function testManagedFile() { // was not saved. $last_fid_prior = $this->getLastFileId(); $edit = [ - $file_field_name => drupal_realpath($test_file->getFileUri()), + $file_field_name => $this->container->get('file_system')->realpath($test_file->getFileUri()), 'form_token' => 'invalid token', ]; $this->drupalPostForm($path, $edit, t('Save')); @@ -46,7 +46,7 @@ function testManagedFile() { // Submit a new file, without using the Upload button. $last_fid_prior = $this->getLastFileId(); - $edit = array($file_field_name => drupal_realpath($test_file->getFileUri())); + $edit = array($file_field_name => $this->container->get('file_system')->realpath($test_file->getFileUri())); $this->drupalPostForm($path, $edit, t('Save')); $last_fid = $this->getLastFileId(); $this->assertTrue($last_fid > $last_fid_prior, 'New file got saved.'); @@ -61,7 +61,7 @@ function testManagedFile() { // Upload, then Submit. $last_fid_prior = $this->getLastFileId(); $this->drupalGet($path); - $edit = array($file_field_name => drupal_realpath($test_file->getFileUri())); + $edit = array($file_field_name => $this->container->get('file_system')->realpath($test_file->getFileUri())); if ($ajax) { $this->drupalPostAjaxForm(NULL, $edit, $input_base_name . '_upload_button'); } @@ -92,7 +92,7 @@ function testManagedFile() { // Upload, then Remove, then Submit. $this->drupalGet($path); - $edit = array($file_field_name => drupal_realpath($test_file->getFileUri())); + $edit = array($file_field_name => $this->container->get('file_system')->realpath($test_file->getFileUri())); if ($ajax) { $this->drupalPostAjaxForm(NULL, $edit, $input_base_name . '_upload_button'); } @@ -120,7 +120,7 @@ function testManagedFile() { // The multiple file upload has additional conditions that need checking. $path = 'file/test/1/1/1'; - $edit = array('files[nested_file][]' => drupal_realpath($test_file->getFileUri())); + $edit = array('files[nested_file][]' => $this->container->get('file_system')->realpath($test_file->getFileUri())); $fid_list = array(); $this->drupalGet($path); @@ -158,7 +158,7 @@ public function testManagedFileRemoved() { $test_file = $this->getTestFile('text'); $file_field_name = 'files[nested_file][]'; - $edit = [$file_field_name => drupal_realpath($test_file->getFileUri())]; + $edit = [$file_field_name => $this->container->get('file_system')->realpath($test_file->getFileUri())]; $this->drupalPostForm(NULL, $edit, t('Upload')); $fid = $this->getLastFileId(); diff --git a/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php index 7987bcf..cc5c415 100644 --- a/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php +++ b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php @@ -86,7 +86,7 @@ public function testSyncedFiles() { // Edit the node to upload a file. $edit = array(); $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[0]->uri); + $edit[$name] = $this->container->get('file_system')->realpath($this->drupalGetTestFiles('text')[0]->uri); $this->drupalPostForm('node/' . $default_language_node->id() . '/edit', $edit, t('Save')); $first_fid = $this->getLastFileId(); @@ -97,7 +97,7 @@ public function testSyncedFiles() { $edit = array(); $edit['title[0][value]'] = 'Bill Murray'; $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[1]->uri); + $edit[$name] = $this->container->get('file_system')->realpath($this->drupalGetTestFiles('text')[1]->uri); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); // This inspects the HTML after the post of the translation, the file // should be displayed on the original node. @@ -123,7 +123,7 @@ public function testSyncedFiles() { $edit = array(); $edit['title[0][value]'] = 'Scarlett Johansson'; $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[2]->uri); + $edit[$name] = $this->container->get('file_system')->realpath($this->drupalGetTestFiles('text')[2]->uri); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); $third_fid = $this->getLastFileId(); @@ -151,7 +151,7 @@ public function testSyncedFiles() { $edit = array(); $edit['title[0][value]'] = 'David Bowie'; $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[3]->uri); + $edit[$name] = $this->container->get('file_system')->realpath($this->drupalGetTestFiles('text')[3]->uri); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); $replaced_second_fid = $this->getLastFileId(); diff --git a/core/modules/file/src/Tests/PrivateFileOnTranslatedEntityTest.php b/core/modules/file/src/Tests/PrivateFileOnTranslatedEntityTest.php index 15039ed..2ab92fa 100644 --- a/core/modules/file/src/Tests/PrivateFileOnTranslatedEntityTest.php +++ b/core/modules/file/src/Tests/PrivateFileOnTranslatedEntityTest.php @@ -80,7 +80,7 @@ public function testPrivateLanguageFile() { // Edit the node to upload a file. $edit = array(); $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[0]->uri); + $edit[$name] = $this->container->get('file_system')->realpath($this->drupalGetTestFiles('text')[0]->uri); $this->drupalPostForm('node/' . $default_language_node->id() . '/edit', $edit, t('Save')); $last_fid_prior = $this->getLastFileId(); @@ -105,7 +105,7 @@ public function testPrivateLanguageFile() { $edit = array(); $edit['title[0][value]'] = $this->randomMachineName(); $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[1]->uri); + $edit[$name] = $this->container->get('file_system')->realpath($this->drupalGetTestFiles('text')[1]->uri); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); $last_fid = $this->getLastFileId(); diff --git a/core/modules/file/src/Tests/SaveUploadTest.php b/core/modules/file/src/Tests/SaveUploadTest.php index 3aaa5cf..f82b336 100644 --- a/core/modules/file/src/Tests/SaveUploadTest.php +++ b/core/modules/file/src/Tests/SaveUploadTest.php @@ -60,7 +60,7 @@ protected function setUp() { // Upload with replace to guarantee there's something there. $edit = array( 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload]' => $this->container->get('file_system')->realpath($this->image->getFileUri()), ); $this->drupalPostForm('file-test/upload', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); @@ -88,7 +88,7 @@ function testNormal() { // Upload a second file. $image2 = current($this->drupalGetTestFiles('image')); - $edit = array('files[file_test_upload]' => drupal_realpath($image2->uri)); + $edit = array('files[file_test_upload]' => $this->container->get('file_system')->realpath($image2->uri)); $this->drupalPostForm('file-test/upload', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); $this->assertRaw(t('You WIN!')); @@ -109,7 +109,7 @@ function testNormal() { // Upload a third file to a subdirectory. $image3 = current($this->drupalGetTestFiles('image')); - $image3_realpath = drupal_realpath($image3->uri); + $image3_realpath = $this->container->get('file_system')->realpath($image3->uri); $dir = $this->randomMachineName(); $edit = array( 'files[file_test_upload]' => $image3_realpath, @@ -132,7 +132,7 @@ function testHandleExtension() { $extensions = 'foo'; $edit = array( 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload]' => $this->container->get('file_system')->realpath($this->image->getFileUri()), 'extensions' => $extensions, ); @@ -152,7 +152,7 @@ function testHandleExtension() { // Now tell file_save_upload() to allow the extension of our test image. $edit = array( 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload]' => $this->container->get('file_system')->realpath($this->image->getFileUri()), 'extensions' => $extensions, ); @@ -170,7 +170,7 @@ function testHandleExtension() { // Now tell file_save_upload() to allow any extension. $edit = array( 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload]' => $this->container->get('file_system')->realpath($this->image->getFileUri()), 'allow_all_extensions' => TRUE, ); $this->drupalPostForm('file-test/upload', $edit, t('Submit')); @@ -191,7 +191,7 @@ function testHandleDangerousFile() { // safety. Also check to make sure its MIME type was changed. $edit = array( 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->phpfile->uri), + 'files[file_test_upload]' => $this->container->get('file_system')->realpath($this->phpfile->uri), 'is_image_file' => FALSE, 'extensions' => 'php', ); @@ -238,7 +238,7 @@ function testHandleFileMunge() { $extensions = $this->imageExtension; $edit = array( - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload]' => $this->container->get('file_system')->realpath($this->image->getFileUri()), 'extensions' => $extensions, ); @@ -260,7 +260,7 @@ function testHandleFileMunge() { file_test_reset(); $edit = array( - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload]' => $this->container->get('file_system')->realpath($this->image->getFileUri()), 'allow_all_extensions' => TRUE, ); @@ -280,7 +280,7 @@ function testHandleFileMunge() { function testExistingRename() { $edit = array( 'file_test_replace' => FILE_EXISTS_RENAME, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload]' => $this->container->get('file_system')->realpath($this->image->getFileUri()) ); $this->drupalPostForm('file-test/upload', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); @@ -296,7 +296,7 @@ function testExistingRename() { function testExistingReplace() { $edit = array( 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload]' => $this->container->get('file_system')->realpath($this->image->getFileUri()) ); $this->drupalPostForm('file-test/upload', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); @@ -312,7 +312,7 @@ function testExistingReplace() { function testExistingError() { $edit = array( 'file_test_replace' => FILE_EXISTS_ERROR, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload]' => $this->container->get('file_system')->realpath($this->image->getFileUri()) ); $this->drupalPostForm('file-test/upload', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); @@ -341,7 +341,7 @@ function testDrupalMovingUploadedFileError() { $edit = array( 'file_subdir' => $test_directory, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload]' => $this->container->get('file_system')->realpath($this->image->getFileUri()) ); \Drupal::state()->set('file_test.disable_error_collection', TRUE); diff --git a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php index c83e143..75dea25 100644 --- a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php +++ b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php @@ -339,7 +339,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin $tmp_file = drupal_tempnam('temporary://', 'generateImage_'); $destination = $tmp_file . '.' . $extension; file_unmanaged_move($tmp_file, $destination, FILE_CREATE_DIRECTORY); - if ($path = $random->image(drupal_realpath($destination), $min_resolution, $max_resolution)) { + if ($path = $random->image(\Drupal::service('file_system')->realpath($destination), $min_resolution, $max_resolution)) { $image = File::create(); $image->setFileUri($path); $image->setOwnerId(\Drupal::currentUser()->id()); diff --git a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php index a0f0274..fad0937 100644 --- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php @@ -302,7 +302,7 @@ public function testDefaultImages() { ); $non_image = $this->drupalGetTestFiles('text'); - $this->drupalPostForm(NULL, array('files[settings_default_image_uuid]' => drupal_realpath($non_image[0]->uri)), t("Upload")); + $this->drupalPostForm(NULL, array('files[settings_default_image_uuid]' => $this->container->get('file_system')->realpath($non_image[0]->uri)), t("Upload")); $this->assertText('The specified file text-0.txt could not be uploaded.'); $this->assertText('Only files with the following extensions are allowed: png gif jpg jpeg.'); diff --git a/core/modules/image/src/Tests/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php index 666a791..d6fa52b 100644 --- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php @@ -299,7 +299,7 @@ function testImageFieldSettings() { // @see FileWidget::formMultipleElements(). $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $field_name . '/storage', array('cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED), t('Save field settings')); $edit = array( - 'files[' . $field_name . '_1][]' => drupal_realpath($test_image->uri), + 'files[' . $field_name . '_1][]' => $this->container->get('file_system')->realpath($test_image->uri), ); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); // Add the required alt text. @@ -309,7 +309,7 @@ function testImageFieldSettings() { // Assert ImageWidget::process() calls FieldWidget::process(). $this->drupalGet('node/' . $node->id() . '/edit'); $edit = array( - 'files[' . $field_name . '_2][]' => drupal_realpath($test_image->uri), + 'files[' . $field_name . '_2][]' => $this->container->get('file_system')->realpath($test_image->uri), ); $this->drupalPostAjaxForm(NULL, $edit, $field_name . '_2_upload_button'); $this->assertNoRaw(''); @@ -344,7 +344,7 @@ function testImageFieldDefaultImage() { $title = $this->randomString(1024); $edit = array( // Get the path of the 'image-test.png' file. - 'files[settings_default_image_uuid]' => drupal_realpath($images[0]->uri), + 'files[settings_default_image_uuid]' => $this->container->get('file_system')->realpath($images[0]->uri), 'settings[default_image][alt]' => $alt, 'settings[default_image][title]' => $title, ); @@ -413,7 +413,7 @@ function testImageFieldDefaultImage() { // Add a default image to the new field. $edit = array( // Get the path of the 'image-test.gif' file. - 'files[settings_default_image_uuid]' => drupal_realpath($images[2]->uri), + 'files[settings_default_image_uuid]' => $this->container->get('file_system')->realpath($images[2]->uri), 'settings[default_image][alt]' => $alt, 'settings[default_image][title]' => $title, ); diff --git a/core/modules/image/src/Tests/ImageFieldTestBase.php b/core/modules/image/src/Tests/ImageFieldTestBase.php index 6081d32..739fc8a 100644 --- a/core/modules/image/src/Tests/ImageFieldTestBase.php +++ b/core/modules/image/src/Tests/ImageFieldTestBase.php @@ -121,7 +121,7 @@ function previewNodeImage($image, $field_name, $type) { $edit = array( 'title[0][value]' => $this->randomMachineName(), ); - $edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri); + $edit['files[' . $field_name . '_0]'] = $this->container->get('file_system')->realpath($image->uri); $this->drupalPostForm('node/add/' . $type, $edit, t('Preview')); } @@ -141,7 +141,7 @@ function uploadNodeImage($image, $field_name, $type, $alt = '') { $edit = array( 'title[0][value]' => $this->randomMachineName(), ); - $edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri); + $edit['files[' . $field_name . '_0]'] = $this->container->get('file_system')->realpath($image->uri); $this->drupalPostForm('node/add/' . $type, $edit, t('Save and publish')); if ($alt) { // Add alt text. diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 1181b50..6bf8432 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -200,7 +200,7 @@ function locale_translate_batch_import($file, array $options, &$context) { try { if (empty($context['sandbox'])) { $context['sandbox']['parse_state'] = array( - 'filesize' => filesize(drupal_realpath($file->uri)), + 'filesize' => filesize(\Drupal::service('file_system')->realpath($file->uri)), 'chunk_size' => 200, 'seek' => 0, ); diff --git a/core/modules/locale/locale.translation.inc b/core/modules/locale/locale.translation.inc index 0383aaf..2ceaa9c 100644 --- a/core/modules/locale/locale.translation.inc +++ b/core/modules/locale/locale.translation.inc @@ -377,7 +377,7 @@ function locale_cron_fill_queue() { function _locale_translation_file_is_remote($uri) { $scheme = file_uri_scheme($uri); if ($scheme) { - return !drupal_realpath($scheme . '://'); + return !\Drupal::service('file_system')->realpath($scheme . '://'); } return FALSE; } diff --git a/core/modules/locale/src/Tests/LocaleUpdateBase.php b/core/modules/locale/src/Tests/LocaleUpdateBase.php index 85196ad..045a6e1 100644 --- a/core/modules/locale/src/Tests/LocaleUpdateBase.php +++ b/core/modules/locale/src/Tests/LocaleUpdateBase.php @@ -138,7 +138,7 @@ protected function makePoFile($path, $filename, $timestamp = NULL, array $transl 'status' => FILE_STATUS_PERMANENT, ]); file_put_contents($file->getFileUri(), $po_header . $text); - touch(drupal_realpath($file->getFileUri()), $timestamp); + touch($this->container->get('file_system')->realpath($file->getFileUri()), $timestamp); $file->save(); } diff --git a/core/modules/locale/src/Tests/LocaleUpdateCronTest.php b/core/modules/locale/src/Tests/LocaleUpdateCronTest.php index 569b818..ae10d0f 100644 --- a/core/modules/locale/src/Tests/LocaleUpdateCronTest.php +++ b/core/modules/locale/src/Tests/LocaleUpdateCronTest.php @@ -43,7 +43,7 @@ public function testUpdateCron() { // Prepare for test: Simulate new translations being available. // Change the last updated timestamp of a translation file. $contrib_module_two_uri = 'public://local/contrib_module_two-8.x-2.0-beta4.de._po'; - touch(drupal_realpath($contrib_module_two_uri), REQUEST_TIME); + touch($this->container->get('file_system')->realpath($contrib_module_two_uri), REQUEST_TIME); // Prepare for test: Simulate that the file has not been checked for a long // time. Set the last_check timestamp to zero. diff --git a/core/modules/node/src/Tests/PagePreviewTest.php b/core/modules/node/src/Tests/PagePreviewTest.php index 2bfd2e7..d13d11c 100644 --- a/core/modules/node/src/Tests/PagePreviewTest.php +++ b/core/modules/node/src/Tests/PagePreviewTest.php @@ -142,7 +142,7 @@ function testPagePreview() { // Upload an image. $test_image = current($this->drupalGetTestFiles('image', 39325)); - $edit['files[field_image_0][]'] = drupal_realpath($test_image->uri); + $edit['files[field_image_0][]'] = $this->container->get('file_system')->realpath($test_image->uri); $this->drupalPostForm('node/add/page', $edit, t('Upload')); // Add an alt tag and preview the node. diff --git a/core/modules/system/src/Form/ThemeSettingsForm.php b/core/modules/system/src/Form/ThemeSettingsForm.php index 7e9893c..7602e6d 100644 --- a/core/modules/system/src/Form/ThemeSettingsForm.php +++ b/core/modules/system/src/Form/ThemeSettingsForm.php @@ -12,6 +12,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\ConfigFormBase; +use Drupal\Core\File\FileSystemInterface; /** * Displays theme configuration for entire site and individual themes. @@ -33,6 +34,12 @@ class ThemeSettingsForm extends ConfigFormBase { protected $themeHandler; /** + * File System instance. + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + + /** * The MIME type guesser. * * @var \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface @@ -57,13 +64,16 @@ class ThemeSettingsForm extends ConfigFormBase { * The theme handler. * @param \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface $mime_type_guesser * The MIME type guesser instance to use. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * The FileSytem instance to use. */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, MimeTypeGuesserInterface $mime_type_guesser) { + public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, MimeTypeGuesserInterface $mime_type_guesser, FileSystemInterface $file_system) { parent::__construct($config_factory); $this->moduleHandler = $module_handler; $this->themeHandler = $theme_handler; $this->mimeTypeGuesser = $mime_type_guesser; + $this->fileSystem = $file_system; } /** @@ -74,7 +84,8 @@ public static function create(ContainerInterface $container) { $container->get('config.factory'), $container->get('module_handler'), $container->get('theme_handler'), - $container->get('file.mime_type.guesser') + $container->get('file.mime_type.guesser'), + $container->get('file_system') ); } @@ -470,7 +481,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { */ protected function validatePath($path) { // Absolute local file paths are invalid. - if (drupal_realpath($path) == $path) { + if ($this->fileSystem->realpath($path) == $path) { return FALSE; } // A path relative to the Drupal root or a fully qualified URI is valid. diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index 7b195cc..bf84019 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -5,6 +5,7 @@ use Drupal\Component\Utility\Color; use Drupal\Component\Utility\Unicode; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\ImageToolkit\ImageToolkitBase; use Drupal\Core\ImageToolkit\ImageToolkitOperationManagerInterface; @@ -60,6 +61,13 @@ class GDToolkit extends ImageToolkitBase { protected $streamWrapperManager; /** + * File System instance. + * + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + + /** * Constructs a GDToolkit object. * * @param array $configuration @@ -76,10 +84,13 @@ class GDToolkit extends ImageToolkitBase { * The config factory. * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager * The StreamWrapper manager. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * The FileSytem instance to use. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger, ConfigFactoryInterface $config_factory, StreamWrapperManagerInterface $stream_wrapper_manager) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger, ConfigFactoryInterface $config_factory, StreamWrapperManagerInterface $stream_wrapper_manager, FileSystemInterface $file_system) { parent::__construct($configuration, $plugin_id, $plugin_definition, $operation_manager, $logger, $config_factory); $this->streamWrapperManager = $stream_wrapper_manager; + $this->fileSystem = $file_system; } /** @@ -104,7 +115,8 @@ public static function create(ContainerInterface $container, array $configuratio $container->get('image.toolkit.operation.manager'), $container->get('logger.channel.image'), $container->get('config.factory'), - $container->get('stream_wrapper_manager') + $container->get('stream_wrapper_manager'), + $container->get('file_system') ); } @@ -224,7 +236,7 @@ public function save($destination) { $destination = drupal_tempnam('temporary://', 'gd_'); } // Convert stream wrapper URI to normal path. - $destination = drupal_realpath($destination); + $destination = $this->fileSystem->realpath($destination); } $function = 'image' . image_type_to_extension($this->getType(), FALSE); diff --git a/core/modules/system/src/Tests/Form/StateValuesCleanAdvancedTest.php b/core/modules/system/src/Tests/Form/StateValuesCleanAdvancedTest.php index eb53244..8c6fe08 100644 --- a/core/modules/system/src/Tests/Form/StateValuesCleanAdvancedTest.php +++ b/core/modules/system/src/Tests/Form/StateValuesCleanAdvancedTest.php @@ -38,7 +38,7 @@ function testFormStateValuesCleanAdvanced() { $this->assertTrue(is_file($this->image->uri), "The image file we're going to upload exists."); // "Browse" for the desired file. - $edit = array('files[image]' => drupal_realpath($this->image->uri)); + $edit = array('files[image]' => $this->container->get('file_system')->realpath($this->image->uri)); // Post the form. $this->drupalPostForm('form_test/form-state-values-clean-advanced', $edit, t('Submit')); diff --git a/core/modules/system/src/Tests/System/ThemeTest.php b/core/modules/system/src/Tests/System/ThemeTest.php index 667c97a..2d65560 100644 --- a/core/modules/system/src/Tests/System/ThemeTest.php +++ b/core/modules/system/src/Tests/System/ThemeTest.php @@ -152,7 +152,7 @@ function testThemeSettings() { // Semi-absolute path to arbitrary non-existing file. '/core/misc/whatever.png', // Absolute paths to any local file (even if it exists). - drupal_realpath($file->uri), + $this->container->get('file_system')->realpath($file->uri), ); $this->drupalGet('admin/appearance/settings'); foreach ($unsupported_paths as $path) { @@ -168,7 +168,7 @@ function testThemeSettings() { $edit = array( 'default_logo' => FALSE, 'logo_path' => '', - 'files[logo_upload]' => drupal_realpath($file->uri), + 'files[logo_upload]' => $this->container->get('file_system')->realpath($file->uri), ); $this->drupalPostForm('admin/appearance/settings', $edit, t('Save configuration')); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 3ef24a5..9c72063 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -427,17 +427,17 @@ function system_requirements($phase) { file_ensure_htaccess(); $htaccess_files['public://.htaccess'] = array( 'title' => t('Public files directory'), - 'directory' => drupal_realpath('public://'), + 'directory' => \Drupal::service('file_system')->realpath('public://'), ); if (PrivateStream::basePath()) { $htaccess_files['private://.htaccess'] = array( 'title' => t('Private files directory'), - 'directory' => drupal_realpath('private://'), + 'directory' => \Drupal::service('file_system')->realpath('private://'), ); } $htaccess_files['temporary://.htaccess'] = array( 'title' => t('Temporary files directory'), - 'directory' => drupal_realpath('temporary://'), + 'directory' => \Drupal::service('file_system')->realpath('temporary://'), ); foreach ($htaccess_files as $htaccess_file => $info) { // Check for the string which was added to the recommended .htaccess file diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 1f553da..872b9dd 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1374,7 +1374,7 @@ function system_retrieve_file($url, $destination = NULL, $managed = FALSE, $repl $path = file_build_uri(drupal_basename($parsed_url['path'])); } else { - if (is_dir(drupal_realpath($destination))) { + if (is_dir(\Drupal::service('file_system')->realpath($destination))) { // Prevent URIs with triple slashes when glueing parts together. $path = str_replace('///', '//', "$destination/") . drupal_basename($parsed_url['path']); } diff --git a/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php b/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php index 306e160..409980e 100644 --- a/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php +++ b/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php @@ -74,7 +74,7 @@ public function testTaxonomyImageAccess() { $files = $this->drupalGetTestFiles('image'); $image = array_pop($files); $edit['name[0][value]'] = $this->randomMachineName(); - $edit['files[field_test_0]'] = drupal_realpath($image->uri); + $edit['files[field_test_0]'] = $this->container->get('file_system')->realpath($image->uri); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save')); $this->drupalPostForm(NULL, ['field_test[0][alt]' => $this->randomMachineName()], t('Save')); $terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $edit['name[0][value]'])); diff --git a/core/modules/text/src/Tests/TextFieldTest.php b/core/modules/text/src/Tests/TextFieldTest.php index 993346a..55a5f99 100644 --- a/core/modules/text/src/Tests/TextFieldTest.php +++ b/core/modules/text/src/Tests/TextFieldTest.php @@ -113,7 +113,7 @@ function testRequiredLongTextWithFileUpload() { ->save(); $test_file = current($this->drupalGetTestFiles('text')); - $edit['files[file_field_0]'] = drupal_realpath($test_file->uri); + $edit['files[file_field_0]'] = $this->container->get('file_system')->realpath($test_file->uri); $this->drupalPostForm('entity_test/add', $edit, 'Upload'); $this->assertResponse(200); $edit = array( diff --git a/core/modules/update/src/Form/UpdateManagerInstall.php b/core/modules/update/src/Form/UpdateManagerInstall.php index 3bc2c78..ff8c208 100644 --- a/core/modules/update/src/Form/UpdateManagerInstall.php +++ b/core/modules/update/src/Form/UpdateManagerInstall.php @@ -212,7 +212,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { return; } - $project_real_location = drupal_realpath($project_location); + $project_real_location = \Drupal::service('file_system')->realpath($project_location); $arguments = array( 'project' => $project, 'updater_name' => get_class($updater), diff --git a/core/modules/update/src/Form/UpdateReady.php b/core/modules/update/src/Form/UpdateReady.php index c8f64a3..93de7ad 100644 --- a/core/modules/update/src/Form/UpdateReady.php +++ b/core/modules/update/src/Form/UpdateReady.php @@ -3,6 +3,7 @@ namespace Drupal\update\Form; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\FileTransfer\Local; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -45,6 +46,13 @@ class UpdateReady extends FormBase { protected $sitePath; /** + * File System instance. + * + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + + /** * Constructs a new UpdateReady object. * * @param string $root @@ -55,12 +63,15 @@ class UpdateReady extends FormBase { * The state key value store. * @param string $site_path * The site path. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * The FileSytem instance to use. */ - public function __construct($root, ModuleHandlerInterface $module_handler, StateInterface $state, $site_path) { + public function __construct($root, ModuleHandlerInterface $module_handler, StateInterface $state, $site_path, FileSystemInterface $file_system) { $this->root = $root; $this->moduleHandler = $module_handler; $this->state = $state; $this->sitePath = $site_path; + $this->fileSystem = $file_system; } /** @@ -78,7 +89,8 @@ public static function create(ContainerInterface $container) { $container->get('update.root'), $container->get('module_handler'), $container->get('state'), - $container->get('site.path') + $container->get('site.path'), + $container->get('file_system') ); } @@ -136,7 +148,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { foreach ($projects as $project => $url) { $project_location = $directory . '/' . $project; $updater = Updater::factory($project_location, $this->root); - $project_real_location = drupal_realpath($project_location); + $project_real_location = $this->fileSystem->realpath($project_location); $updates[] = array( 'project' => $project, 'updater_name' => get_class($updater), diff --git a/core/modules/update/src/Tests/UpdateDeleteFileIfStaleTest.php b/core/modules/update/src/Tests/UpdateDeleteFileIfStaleTest.php index 63c2889..d209fd1 100644 --- a/core/modules/update/src/Tests/UpdateDeleteFileIfStaleTest.php +++ b/core/modules/update/src/Tests/UpdateDeleteFileIfStaleTest.php @@ -38,7 +38,7 @@ function testUpdateDeleteFileIfStale() { ->set('temporary_maximum_age', -100000) ->save(); - $file_path = drupal_realpath($file_name); + $file_path = $this->container->get('file_system')->realpath($file_name); update_delete_file_if_stale($file_path); $this->assertFalse(is_file($file_path)); diff --git a/core/modules/update/update.manager.inc b/core/modules/update/update.manager.inc index f9c7c5f..efc94e6 100644 --- a/core/modules/update/update.manager.inc +++ b/core/modules/update/update.manager.inc @@ -208,7 +208,7 @@ function update_manager_file_get($url) { $remote_schemes = array('http', 'https', 'ftp', 'ftps', 'smb', 'nfs'); if (!isset($parsed_url['scheme']) || !in_array($parsed_url['scheme'], $remote_schemes)) { // This is a local file, just return the path. - return drupal_realpath($url); + return \Drupal::service('file_system')->realpath($url); } // Check the cache and download the file if needed. diff --git a/core/modules/user/src/Tests/UserPasswordResetTest.php b/core/modules/user/src/Tests/UserPasswordResetTest.php index c012e9f..d696014 100644 --- a/core/modules/user/src/Tests/UserPasswordResetTest.php +++ b/core/modules/user/src/Tests/UserPasswordResetTest.php @@ -118,7 +118,7 @@ function testUserPasswordReset() { // invalidate the reset token. $image = current($this->drupalGetTestFiles('image')); $edit = array( - 'files[user_picture_0]' => drupal_realpath($image->uri), + 'files[user_picture_0]' => $this->container->get('file_system')->realpath($image->uri), ); $this->drupalPostAjaxForm(NULL, $edit, 'user_picture_0_upload_button'); diff --git a/core/modules/user/src/Tests/UserPictureTest.php b/core/modules/user/src/Tests/UserPictureTest.php index 3f8db42..d405b21 100644 --- a/core/modules/user/src/Tests/UserPictureTest.php +++ b/core/modules/user/src/Tests/UserPictureTest.php @@ -130,7 +130,7 @@ function testPictureOnNodeComment() { * Edits the user picture for the test user. */ function saveUserPicture($image) { - $edit = array('files[user_picture_0]' => drupal_realpath($image->uri)); + $edit = array('files[user_picture_0]' => $this->container->get('file_system')->realpath($image->uri)); $this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $edit, t('Save')); // Load actual user data from database. diff --git a/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php b/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php index 774bd7c..5b2baa2 100644 --- a/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php @@ -45,7 +45,7 @@ function testFileCheckLocalDirectoryHandling() { $this->assertDirectoryPermissions($directory, $old_mode); // Check creating a directory using an absolute path. - $absolute_path = drupal_realpath($directory) . DIRECTORY_SEPARATOR . $this->randomMachineName() . DIRECTORY_SEPARATOR . $this->randomMachineName(); + $absolute_path = $this->container->get('file_system')->realpath($directory) . DIRECTORY_SEPARATOR . $this->randomMachineName() . DIRECTORY_SEPARATOR . $this->randomMachineName(); $this->assertTrue(drupal_mkdir($absolute_path, 0775, TRUE), 'No error reported when creating new absolute directories.', 'File'); $this->assertDirectoryPermissions($absolute_path, 0775); }