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\UtilCode
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));
}
}