}
// 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]);
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 {
}
// 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]);
}
// 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
*
* @param $path
* A string containing either an URI or a file or directory path.
- * @param $callback
+ * @param callable $callback
* (optional) Callback function to run on each file prior to deleting it and
* on each directory prior to traversing it. For example, can be used to
* modify permissions.