--- 1395524-28.patch 2018-04-02 20:03:21.000000000 +0530 +++ 1395524-40.patch 2022-06-02 19:56:55.000000000 +0530 @@ -1,46 +1,15 @@ -diff --git a/core/includes/file.inc b/core/includes/file.inc -index 83df3a2..4d6504c 100644 ---- a/core/includes/file.inc -+++ b/core/includes/file.inc -@@ -927,17 +927,39 @@ function file_unmanaged_delete_recursive($path, $callback = NULL) { - return file_unmanaged_delete($path); - } - -- - /** - * Moves an uploaded file to a new location. - * -+ * PHP's move_uploaded_file() does not properly support URIs if safe_mode or -+ * open_basedir are enabled, so this function fills that gap for local URIs. -+ * -+ * move_uploaded_file() is also very inefficient when supplied with URIs as it -+ * will perform a copy and then a delete. With this function, if the destination -+ * URI scheme supports the realpath() method, i.e. it is a local scheme, then -+ * the I/O produced will be negligible. -+ * -+ * Compatibility: normal paths and stream wrappers. -+ * -+ * @param $filename -+ * The filename of the uploaded file. -+ * @param $uri -+ * A string containing the destination URI of the file. -+ * -+ * @return -+ * TRUE on success, or FALSE on failure. -+ * -+ * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. -+ * Use \Drupal\Core\File\FileSystem::realpath(). -+ * - * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. - * Use \Drupal\Core\File\FileSystem::moveUploadedFile(). - * - * @see https://www.drupal.org/node/2418133 - */ - function drupal_move_uploaded_file($filename, $uri) { -- return \Drupal::service('file_system')->moveUploadedFile($filename, $uri); -+ // Resolve the destination URI if posible. -+ $destination = drupal_realpath($uri) ?: $uri; -+ return \Drupal::service('file_system')->moveUploadedFile($filename, $destination); - } - - /** +diff --git a/core/lib/Drupal/Core/File/FileSystem.php b/core/lib/Drupal/Core/File/FileSystem.php +index 02175f9..e7fe451 100644 +--- a/core/lib/Drupal/Core/File/FileSystem.php ++++ b/core/lib/Drupal/Core/File/FileSystem.php +@@ -73,7 +73,9 @@ public function __construct(StreamWrapperManagerInterface $stream_wrapper_manage + * {@inheritdoc} + */ + public function moveUploadedFile($filename, $uri) { +- $result = @move_uploaded_file($filename, $uri); ++ // Resolved the destination URI. ++ $destination = \Drupal::service('file_system')->realpath($uri) ?: $uri; ++ $result = \Drupal::service('file_system')->moveUploadedFile($filename, $destination); + // PHP's move_uploaded_file() does not properly support streams if + // open_basedir is enabled so if the move failed, try finding a real path + // and retry the move operation.