public function FileSystem::move in Drupal 10        
                          
                  
                        Same name and namespace in other branches
- 8 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::move()
- 9 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::move()
File
 
   - core/lib/Drupal/Core/File/FileSystem.php, line 378
Class
  
  - FileSystem 
- Provides helpers to operate on files and stream wrappers.
Namespace
  Drupal\Core\File
Code
public function move($source, $destination, $replace = self::EXISTS_RENAME) {
  $this
    ->prepareDestination($source, $destination, $replace);
  
  if (!$this->streamWrapperManager
    ->isValidUri($source) && substr(PHP_OS, 0, 3) == 'WIN') {
    chmod($source, 0600);
  }
  
  $real_source = $this
    ->realpath($source) ?: $source;
  $real_destination = $this
    ->realpath($destination) ?: $destination;
  
  if (!@rename($real_source, $real_destination)) {
    
    if (!@copy($real_source, $real_destination)) {
      $this->logger
        ->error("The specified file '%source' could not be moved to '%destination'.", [
        '%source' => $source,
        '%destination' => $destination,
      ]);
      throw new FileWriteException("The specified file '{$source}' could not be moved to '{$destination}'.");
    }
    if (!@unlink($real_source)) {
      $this->logger
        ->error("The source file '%source' could not be unlinked after copying to '%destination'.", [
        '%source' => $source,
        '%destination' => $destination,
      ]);
      throw new FileException("The source file '{$source}' could not be unlinked after copying to '{$destination}'.");
    }
  }
  
  $this
    ->chmod($destination);
  return $destination;
}