Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Filesystem.php

function Filesystem::rename

Same name in this branch
  1. 11.1.x vendor/symfony/filesystem/Filesystem.php \Symfony\Component\Filesystem\Filesystem::rename()

Return value

void

File

vendor/composer/composer/src/Composer/Util/Filesystem.php, line 416

Class

Filesystem
@author Jordi Boggiano <j.boggiano@seld.be> @author Johannes M. Schmitt <schmittjoh@gmail.com>

Namespace

Composer\Util

Code

public function rename(string $source, string $target) {
    if (true === @rename($source, $target)) {
        return;
    }
    if (!\function_exists('proc_open')) {
        $this->copyThenRemove($source, $target);
        return;
    }
    if (Platform::isWindows()) {
        // Try to copy & delete - this is a workaround for random "Access denied" errors.
        $result = $this->getProcess()
            ->execute([
            'xcopy',
            $source,
            $target,
            '/E',
            '/I',
            '/Q',
            '/Y',
        ], $output);
        // clear stat cache because external processes aren't tracked by the php stat cache
        clearstatcache();
        if (0 === $result) {
            $this->remove($source);
            return;
        }
    }
    else {
        // We do not use PHP's "rename" function here since it does not support
        // the case where $source, and $target are located on different partitions.
        $result = $this->getProcess()
            ->execute([
            'mv',
            $source,
            $target,
        ], $output);
        // clear stat cache because external processes aren't tracked by the php stat cache
        clearstatcache();
        if (0 === $result) {
            return;
        }
    }
    $this->copyThenRemove($source, $target);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal