diff --git a/core/includes/common.inc b/core/includes/common.inc index 323a666..9bb16f7 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', ['%file' => $file])); } diff --git a/core/includes/file.inc b/core/includes/file.inc index c78ee5b..76f5773 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -452,8 +452,9 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST } // Attempt to resolve the URIs. This is necessary in certain configurations // (see above). - $real_source = drupal_realpath($source) ?: $source; - $real_destination = drupal_realpath($destination) ?: $destination; + $file_system = \Drupal::service('file_system'); + $real_source = $file_system->realpath($source) ?: $source; + $real_destination = $file_system->realpath($destination) ?: $destination; // Perform the copy operation. if (!@copy($real_source, $real_destination)) { \Drupal::logger('file')->error('The specified file %file could not be copied to %destination.', ['%file' => $source, '%destination' => $destination]); @@ -497,12 +498,13 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_EXISTS_RENAME) { $original_source = $source; $logger = \Drupal::logger('file'); + $file_system = \Drupal::service('file_system'); // Assert that the source file actually exists. 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.', ['%file' => $original_source]), 'error'); - if (($realpath = drupal_realpath($original_source)) !== FALSE) { + if (($realpath = $file_system->realpath($original_source)) !== FALSE) { $logger->notice('File %file (%realpath) could not be moved/copied because it does not exist.', ['%file' => $original_source, '%realpath' => $realpath]); } else { @@ -542,8 +544,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 = $file_system->realpath($source); + $real_destination = $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.', ['%file' => $source]), 'error'); $logger->notice('File %file could not be moved/copied because it would overwrite itself.', ['%file' => $source]); @@ -643,8 +645,9 @@ function file_unmanaged_move($source, $destination = NULL, $replace = FILE_EXIST } // Attempt to resolve the URIs. This is necessary in certain configurations // (see above) and can also permit fast moves across local schemes. - $real_source = drupal_realpath($source) ?: $source; - $real_destination = drupal_realpath($destination) ?: $destination; + $file_system = \Drupal::service('file_system'); + $real_source = $file_system->realpath($source) ?: $source; + $real_destination = $file_system->realpath($destination) ?: $destination; // Perform the move operation. if (!@rename($real_source, $real_destination)) { // Fall back to slow copy and unlink procedure. This is necessary for diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index cfc0497..7a434c4 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1375,7 +1375,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 25014f1..79becc8 100644 --- a/core/lib/Drupal/Core/FileTransfer/FileTransfer.php +++ b/core/lib/Drupal/Core/FileTransfer/FileTransfer.php @@ -207,7 +207,7 @@ public 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, ['@directory' => $path, '@jail' => $this->jail]); diff --git a/core/modules/color/color.module b/core/modules/color/color.module index 20d099a..25d4874 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 11ff1e7..2cd915f 100644 --- a/core/modules/color/tests/src/Functional/ColorTest.php +++ b/core/modules/color/tests/src/Functional/ColorTest.php @@ -141,7 +141,7 @@ public function _testColor($theme, $test_values) { $stylesheets = \Drupal::state()->get('drupal_css_cache_files') ?: []; $stylesheet_content = ''; foreach ($stylesheets as $uri) { - $stylesheet_content .= join("\n", file(drupal_realpath($uri))); + $stylesheet_content .= join("\n", file(\Drupal::service('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 1b07fe6..89cea53 100644 --- a/core/modules/comment/src/Tests/CommentPreviewTest.php +++ b/core/modules/comment/src/Tests/CommentPreviewTest.php @@ -55,7 +55,7 @@ public 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]'] = \Drupal::service('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 5e21295..4214f72 100644 --- a/core/modules/config/src/Tests/ConfigImportUploadTest.php +++ b/core/modules/config/src/Tests/ConfigImportUploadTest.php @@ -42,7 +42,7 @@ public function testImport() { // Attempt to upload a non-tar file. $text_file = current($this->drupalGetTestFiles('text')); - $edit = ['files[import_tarball]' => drupal_realpath($text_file->uri)]; + $edit = ['files[import_tarball]' => \Drupal::service('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/editor/src/Tests/EditorUploadImageScaleTest.php b/core/modules/editor/src/Tests/EditorUploadImageScaleTest.php index 5ac88c7..100fb4f 100644 --- a/core/modules/editor/src/Tests/EditorUploadImageScaleTest.php +++ b/core/modules/editor/src/Tests/EditorUploadImageScaleTest.php @@ -188,7 +188,7 @@ protected function setMaxDimensions($width, $height) { */ protected function uploadImage($uri) { $edit = [ - 'files[fid]' => drupal_realpath($uri), + 'files[fid]' => \Drupal::service('file_system')->realpath($uri), ]; $this->drupalGet('editor/dialog/image/basic_html'); $this->drupalPostForm('editor/dialog/image/basic_html', $edit, t('Upload')); diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceFileUploadTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceFileUploadTest.php index 1957584..fc21e50 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]'] = \Drupal::service('file_system')->realpath($test_file->uri); $this->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Upload'); $this->assertResponse(200); $edit = [ diff --git a/core/modules/file/file.module b/core/modules/file/file.module index a6fc3f6..5201290 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.', ['%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.', ['%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 1b7e534..cce0821 100644 --- a/core/modules/file/src/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/src/Tests/FileFieldDisplayTest.php @@ -96,7 +96,7 @@ public 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] = \Drupal::service('file_system')->realpath($test_file->getFileUri()); // Uncheck the display checkboxes and go to the preview. $edit[$field_name . '[0][display]'] = FALSE; @@ -165,7 +165,7 @@ public function testDescToggle() { $title = $this->randomString(); $edit = [ 'title[0][value]' => $title, - 'files[field_' . $field_name . '_0]' => drupal_realpath($file->uri), + 'files[field_' . $field_name . '_0]' => \Drupal::service('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 73cc96a..99e2c58 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php @@ -251,7 +251,7 @@ public function removeNodeFile($nid, $new_revision = TRUE) { */ public function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) { $edit = [ - 'files[' . $field_name . '_0]' => drupal_realpath($file->getFileUri()), + 'files[' . $field_name . '_0]' => \Drupal::service('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 ddfd8f4..a867d65 100644 --- a/core/modules/file/src/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php @@ -160,7 +160,7 @@ public function testMultiValuedWidget() { $this->drupalGet("node/add/$type_name"); foreach ([$field_name2, $field_name] as $each_field_name) { for ($delta = 0; $delta < 3; $delta++) { - $edit = ['files[' . $each_field_name . '_' . $delta . '][]' => drupal_realpath($test_file->getFileUri())]; + $edit = ['files[' . $each_field_name . '_' . $delta . '][]' => \Drupal::service('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 @@ public function testPrivateFileComment() { // Add a comment with a file. $text_file = $this->getTestFile('text'); $edit = [ - 'files[field_' . $name . '_' . 0 . ']' => drupal_realpath($text_file->getFileUri()), + 'files[field_' . $name . '_' . 0 . ']' => \Drupal::service('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 @@ public 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] = \Drupal::service('file_system')->realpath($test_file_image->getFileUri()); switch ($type) { case 'nojs': $this->drupalPostForm(NULL, $edit, t('Upload')); @@ -443,7 +443,7 @@ public function testWidgetValidation() { $this->assertRaw($error_message, t('Validation error when file with wrong extension uploaded (JSMode=%type).', ['%type' => $type])); // Upload file with correct extension, check that error message is removed. - $edit[$name] = drupal_realpath($test_file_text->getFileUri()); + $edit[$name] = \Drupal::service('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 e348949..12c7ce2 100644 --- a/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/src/Tests/FileListingTest.php @@ -91,7 +91,7 @@ public function testFileListingPages() { $file = $this->getTestFile('image'); $edit = [ - 'files[file_0]' => drupal_realpath($file->getFileUri()), + 'files[file_0]' => \Drupal::service('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 8abff25..897cc37 100644 --- a/core/modules/file/src/Tests/FileManagedFileElementTest.php +++ b/core/modules/file/src/Tests/FileManagedFileElementTest.php @@ -36,7 +36,7 @@ public function testManagedFile() { // was not saved. $last_fid_prior = $this->getLastFileId(); $edit = [ - $file_field_name => drupal_realpath($test_file->getFileUri()), + $file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri()), 'form_token' => 'invalid token', ]; $this->drupalPostForm($path, $edit, t('Save')); @@ -46,7 +46,7 @@ public function testManagedFile() { // Submit a new file, without using the Upload button. $last_fid_prior = $this->getLastFileId(); - $edit = [$file_field_name => drupal_realpath($test_file->getFileUri())]; + $edit = [$file_field_name => \Drupal::service('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 @@ public function testManagedFile() { // Upload, then Submit. $last_fid_prior = $this->getLastFileId(); $this->drupalGet($path); - $edit = [$file_field_name => drupal_realpath($test_file->getFileUri())]; + $edit = [$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri())]; if ($ajax) { $this->drupalPostAjaxForm(NULL, $edit, $input_base_name . '_upload_button'); } @@ -92,7 +92,7 @@ public function testManagedFile() { // Upload, then Remove, then Submit. $this->drupalGet($path); - $edit = [$file_field_name => drupal_realpath($test_file->getFileUri())]; + $edit = [$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri())]; if ($ajax) { $this->drupalPostAjaxForm(NULL, $edit, $input_base_name . '_upload_button'); } @@ -120,7 +120,7 @@ public function testManagedFile() { // The multiple file upload has additional conditions that need checking. $path = 'file/test/1/1/1'; - $edit = ['files[nested_file][]' => drupal_realpath($test_file->getFileUri())]; + $edit = ['files[nested_file][]' => \Drupal::service('file_system')->realpath($test_file->getFileUri())]; $fid_list = []; $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 => \Drupal::service('file_system')->realpath($test_file->getFileUri())]; $this->drupalPostForm(NULL, $edit, t('Upload')); $fid = $this->getLastFileId(); @@ -179,7 +179,7 @@ public function testFileRemovedFromDisk() { $test_file = $this->getTestFile('text'); $file_field_name = 'files[nested_file][]'; - $edit = [$file_field_name => drupal_realpath($test_file->getFileUri())]; + $edit = [$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri())]; $this->drupalPostForm(NULL, $edit, t('Upload')); $this->drupalPostForm(NULL, [], t('Save')); diff --git a/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php index 5f1e707..6875fe0 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 = []; $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[0]->uri); + $edit[$name] = \Drupal::service('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 = []; $edit['title[0][value]'] = 'Bill Murray'; $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[1]->uri); + $edit[$name] = \Drupal::service('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 = []; $edit['title[0][value]'] = 'Scarlett Johansson'; $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[2]->uri); + $edit[$name] = \Drupal::service('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 = []; $edit['title[0][value]'] = 'David Bowie'; $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[3]->uri); + $edit[$name] = \Drupal::service('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 da5abb5..2712ce0 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 = []; $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[0]->uri); + $edit[$name] = \Drupal::service('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 = []; $edit['title[0][value]'] = $this->randomMachineName(); $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[1]->uri); + $edit[$name] = \Drupal::service('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 a9f69c2..a6e6f9a 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 = [ 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload]' => \Drupal::service('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 @@ public function testNormal() { // Upload a second file. $image2 = current($this->drupalGetTestFiles('image')); - $edit = ['files[file_test_upload]' => drupal_realpath($image2->uri)]; + $edit = ['files[file_test_upload]' => \Drupal::service('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 @@ public function testNormal() { // Upload a third file to a subdirectory. $image3 = current($this->drupalGetTestFiles('image')); - $image3_realpath = drupal_realpath($image3->uri); + $image3_realpath = \Drupal::service('file_system')->realpath($image3->uri); $dir = $this->randomMachineName(); $edit = [ 'files[file_test_upload]' => $image3_realpath, @@ -132,7 +132,7 @@ public function testHandleExtension() { $extensions = 'foo'; $edit = [ 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()), 'extensions' => $extensions, ]; @@ -152,7 +152,7 @@ public function testHandleExtension() { // Now tell file_save_upload() to allow the extension of our test image. $edit = [ 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()), 'extensions' => $extensions, ]; @@ -170,7 +170,7 @@ public function testHandleExtension() { // Now tell file_save_upload() to allow any extension. $edit = [ 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()), 'allow_all_extensions' => TRUE, ]; $this->drupalPostForm('file-test/upload', $edit, t('Submit')); @@ -191,7 +191,7 @@ public function testHandleDangerousFile() { // safety. Also check to make sure its MIME type was changed. $edit = [ 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->phpfile->uri), + 'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->phpfile->uri), 'is_image_file' => FALSE, 'extensions' => 'php', ]; @@ -238,7 +238,7 @@ public function testHandleFileMunge() { $extensions = $this->imageExtension; $edit = [ - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()), 'extensions' => $extensions, ]; @@ -260,7 +260,7 @@ public function testHandleFileMunge() { file_test_reset(); $edit = [ - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()), 'allow_all_extensions' => TRUE, ]; @@ -280,7 +280,7 @@ public function testHandleFileMunge() { public function testExistingRename() { $edit = [ 'file_test_replace' => FILE_EXISTS_RENAME, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload]' => \Drupal::service('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 @@ public function testExistingRename() { public function testExistingReplace() { $edit = [ 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload]' => \Drupal::service('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 @@ public function testExistingReplace() { public function testExistingError() { $edit = [ 'file_test_replace' => FILE_EXISTS_ERROR, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload]' => \Drupal::service('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 @@ public function testDrupalMovingUploadedFileError() { $edit = [ 'file_subdir' => $test_directory, - 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload]' => \Drupal::service('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 7b8b275..4acb6f6 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 d04a1c4..22d0e01 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, ['files[settings_default_image_uuid]' => drupal_realpath($non_image[0]->uri)], t("Upload")); + $this->drupalPostForm(NULL, ['files[settings_default_image_uuid]' => \Drupal::service('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 9c105c1..2e1edf4 100644 --- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php @@ -312,7 +312,7 @@ public function testImageFieldSettings() { // @see FileWidget::formMultipleElements(). $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $field_name . '/storage', ['cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED], t('Save field settings')); $edit = [ - 'files[' . $field_name . '_1][]' => drupal_realpath($test_image->uri), + 'files[' . $field_name . '_1][]' => \Drupal::service('file_system')->realpath($test_image->uri), ]; $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); // Add the required alt text. @@ -322,7 +322,7 @@ public function testImageFieldSettings() { // Assert ImageWidget::process() calls FieldWidget::process(). $this->drupalGet('node/' . $node->id() . '/edit'); $edit = [ - 'files[' . $field_name . '_2][]' => drupal_realpath($test_image->uri), + 'files[' . $field_name . '_2][]' => \Drupal::service('file_system')->realpath($test_image->uri), ]; $this->drupalPostAjaxForm(NULL, $edit, $field_name . '_2_upload_button'); $this->assertNoRaw(''); @@ -357,7 +357,7 @@ public function testImageFieldDefaultImage() { $title = $this->randomString(1024); $edit = [ // Get the path of the 'image-test.png' file. - 'files[settings_default_image_uuid]' => drupal_realpath($images[0]->uri), + 'files[settings_default_image_uuid]' => \Drupal::service('file_system')->realpath($images[0]->uri), 'settings[default_image][alt]' => $alt, 'settings[default_image][title]' => $title, ]; @@ -426,7 +426,7 @@ public function testImageFieldDefaultImage() { // Add a default image to the new field. $edit = [ // Get the path of the 'image-test.gif' file. - 'files[settings_default_image_uuid]' => drupal_realpath($images[2]->uri), + 'files[settings_default_image_uuid]' => \Drupal::service('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 eec7f7b..9cddf35 100644 --- a/core/modules/image/src/Tests/ImageFieldTestBase.php +++ b/core/modules/image/src/Tests/ImageFieldTestBase.php @@ -69,7 +69,7 @@ public function previewNodeImage($image, $field_name, $type) { $edit = [ 'title[0][value]' => $this->randomMachineName(), ]; - $edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri); + $edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')->realpath($image->uri); $this->drupalPostForm('node/add/' . $type, $edit, t('Preview')); } @@ -89,7 +89,7 @@ public function uploadNodeImage($image, $field_name, $type, $alt = '') { $edit = [ 'title[0][value]' => $this->randomMachineName(), ]; - $edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri); + $edit['files[' . $field_name . '_0]'] = \Drupal::service('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/image/src/Tests/ImageOnTranslatedEntityTest.php b/core/modules/image/src/Tests/ImageOnTranslatedEntityTest.php index e1f70d7..23a6592 100644 --- a/core/modules/image/src/Tests/ImageOnTranslatedEntityTest.php +++ b/core/modules/image/src/Tests/ImageOnTranslatedEntityTest.php @@ -92,7 +92,7 @@ public function testSyncedImages() { // Edit the node to upload a file. $edit = []; $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('image')[0]->uri); + $edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[0]->uri); $this->drupalPostForm('node/' . $default_language_node->id() . '/edit', $edit, t('Save')); $edit = [$this->fieldName . '[0][alt]' => 'Lost in translation image', $this->fieldName . '[0][title]' => 'Lost in translation image title']; $this->drupalPostForm(NULL, $edit, t('Save')); @@ -105,7 +105,7 @@ public function testSyncedImages() { $edit = []; $edit['title[0][value]'] = 'Scarlett Johansson'; $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('image')[1]->uri); + $edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[1]->uri); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); $edit = [$this->fieldName . '[0][alt]' => 'Scarlett Johansson image', $this->fieldName . '[0][title]' => 'Scarlett Johansson image title']; $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); @@ -137,7 +137,7 @@ public function testSyncedImages() { $edit = []; $edit['title[0][value]'] = 'Akiko Takeshita'; $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('image')[2]->uri); + $edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[2]->uri); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); $edit = [$this->fieldName . '[0][alt]' => 'Akiko Takeshita image', $this->fieldName . '[0][title]' => 'Akiko Takeshita image title']; $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); @@ -172,7 +172,7 @@ public function testSyncedImages() { $edit = []; $edit['title[0][value]'] = 'Giovanni Ribisi'; $name = 'files[' . $this->fieldName . '_0]'; - $edit[$name] = drupal_realpath($this->drupalGetTestFiles('image')[3]->uri); + $edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[3]->uri); $this->drupalPostForm(NULL, $edit, t('Save (this translation)')); $name = $this->fieldName . '[0][alt]'; diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 3e256c2..6beb3fe 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'] = [ - '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 571f7d2..526a06c 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 b228a96..7b98a49 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(\Drupal::service('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 78a14ec..8e94c80 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(\Drupal::service('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 37b00d3..64bc077 100644 --- a/core/modules/node/src/Tests/PagePreviewTest.php +++ b/core/modules/node/src/Tests/PagePreviewTest.php @@ -171,7 +171,7 @@ public 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][]'] = \Drupal::service('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 f5cfb09..5de532d 100644 --- a/core/modules/system/src/Form/ThemeSettingsForm.php +++ b/core/modules/system/src/Form/ThemeSettingsForm.php @@ -480,7 +480,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 (\Drupal::service('file_system')->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 818c5b5..308a807 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -224,7 +224,7 @@ public function save($destination) { $destination = drupal_tempnam('temporary://', 'gd_'); } // Convert stream wrapper URI to normal path. - $destination = drupal_realpath($destination); + $destination = \Drupal::service('file_system')->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 976209e..9f4353e 100644 --- a/core/modules/system/src/Tests/Form/StateValuesCleanAdvancedTest.php +++ b/core/modules/system/src/Tests/Form/StateValuesCleanAdvancedTest.php @@ -38,7 +38,7 @@ public function testFormStateValuesCleanAdvanced() { $this->assertTrue(is_file($this->image->uri), "The image file we're going to upload exists."); // "Browse" for the desired file. - $edit = ['files[image]' => drupal_realpath($this->image->uri)]; + $edit = ['files[image]' => \Drupal::service('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 29d88a3..a02680e 100644 --- a/core/modules/system/src/Tests/System/ThemeTest.php +++ b/core/modules/system/src/Tests/System/ThemeTest.php @@ -152,7 +152,7 @@ public 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), + \Drupal::service('file_system')->realpath($file->uri), ]; $this->drupalGet('admin/appearance/settings'); foreach ($unsupported_paths as $path) { @@ -168,7 +168,7 @@ public function testThemeSettings() { $edit = [ 'default_logo' => FALSE, 'logo_path' => '', - 'files[logo_upload]' => drupal_realpath($file->uri), + 'files[logo_upload]' => \Drupal::service('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 614ad9e..ba8321b 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -466,19 +466,20 @@ function system_requirements($phase) { // Try to write the .htaccess files first, to prevent false alarms in case // (for example) the /tmp directory was wiped. file_ensure_htaccess(); + $file_system = \Drupal::service('file_system'); $htaccess_files['public://.htaccess'] = [ 'title' => t('Public files directory'), - 'directory' => drupal_realpath('public://'), + 'directory' => $file_system->realpath('public://'), ]; if (PrivateStream::basePath()) { $htaccess_files['private://.htaccess'] = [ 'title' => t('Private files directory'), - 'directory' => drupal_realpath('private://'), + 'directory' => $file_system->realpath('private://'), ]; } $htaccess_files['temporary://.htaccess'] = [ 'title' => t('Temporary files directory'), - 'directory' => drupal_realpath('temporary://'), + 'directory' => $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 a1a6b71..49bb5cc 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1410,7 +1410,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 7d2ee2b..94a9792 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]'] = \Drupal::service('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', ['name' => $edit['name[0][value]']]); diff --git a/core/modules/text/src/Tests/TextFieldTest.php b/core/modules/text/src/Tests/TextFieldTest.php index d061c00..f3fb43f 100644 --- a/core/modules/text/src/Tests/TextFieldTest.php +++ b/core/modules/text/src/Tests/TextFieldTest.php @@ -113,7 +113,7 @@ public function testRequiredLongTextWithFileUpload() { ->save(); $test_file = current($this->drupalGetTestFiles('text')); - $edit['files[file_field_0]'] = drupal_realpath($test_file->uri); + $edit['files[file_field_0]'] = \Drupal::service('file_system')->realpath($test_file->uri); $this->drupalPostForm('entity_test/add', $edit, 'Upload'); $this->assertResponse(200); $edit = [ diff --git a/core/modules/update/src/Form/UpdateManagerInstall.php b/core/modules/update/src/Form/UpdateManagerInstall.php index b141182..9278c2b 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 = [ '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 ef9a2f1..1965dfe 100644 --- a/core/modules/update/src/Form/UpdateReady.php +++ b/core/modules/update/src/Form/UpdateReady.php @@ -136,7 +136,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 = \Drupal::service('file_system')->realpath($project_location); $updates[] = [ '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 99499d7..7e18dd2 100644 --- a/core/modules/update/src/Tests/UpdateDeleteFileIfStaleTest.php +++ b/core/modules/update/src/Tests/UpdateDeleteFileIfStaleTest.php @@ -38,7 +38,7 @@ public function testUpdateDeleteFileIfStale() { ->set('temporary_maximum_age', -100000) ->save(); - $file_path = drupal_realpath($file_name); + $file_path = \Drupal::service('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 e796007..8c9e14a 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 = ['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 528d38b..77a9b2e 100644 --- a/core/modules/user/src/Tests/UserPasswordResetTest.php +++ b/core/modules/user/src/Tests/UserPasswordResetTest.php @@ -118,7 +118,7 @@ public function testUserPasswordReset() { // invalidate the reset token. $image = current($this->drupalGetTestFiles('image')); $edit = [ - 'files[user_picture_0]' => drupal_realpath($image->uri), + 'files[user_picture_0]' => \Drupal::service('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 6d546f0..bda7bdb 100644 --- a/core/modules/user/src/Tests/UserPictureTest.php +++ b/core/modules/user/src/Tests/UserPictureTest.php @@ -130,7 +130,7 @@ public function testPictureOnNodeComment() { * Edits the user picture for the test user. */ public function saveUserPicture($image) { - $edit = ['files[user_picture_0]' => drupal_realpath($image->uri)]; + $edit = ['files[user_picture_0]' => \Drupal::service('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 4e35821..467d926 100644 --- a/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php @@ -45,7 +45,7 @@ public 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 = \Drupal::service('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); }