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

Breadcrumb

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

function Filesystem::safeCopy

Copy file using stream_copy_to_stream to work around https://bugs.php.net/bug.php?id=6463

File

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

Class

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

Namespace

Composer\Util

Code

public function safeCopy(string $source, string $target) : void {
    if (!file_exists($target) || !file_exists($source) || !$this->filesAreEqual($source, $target)) {
        $sourceHandle = fopen($source, 'r');
        assert($sourceHandle !== false, 'Could not open "' . $source . '" for reading.');
        $targetHandle = fopen($target, 'w+');
        assert($targetHandle !== false, 'Could not open "' . $target . '" for writing.');
        stream_copy_to_stream($sourceHandle, $targetHandle);
        fclose($sourceHandle);
        fclose($targetHandle);
        touch($target, (int) filemtime($source), (int) fileatime($source));
    }
}

API Navigation

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