Resources/Private/ExtensionArtifacts/Classes/Console/Hook/ExtensionInstallation.php
private function safeCopy($fullSourcePath, $fullTargetPath, $relativeWebDir = '')
    {
        if (file_exists($fullTargetPath)) {
            if (!is_file($fullTargetPath)) {
                // Seems to be a directory: ignore
                return false;
            }
            if (!self::isTypo3CmsBinary($fullTargetPath)) {
                // File is there but does not seem to be a previous version of our script: better ignore
                return false;
            }
        }
        if ($this->isWindowsOs()) {
            $success = @copy($fullSourcePath, $fullTargetPath);
        } else {
            $proxyFileContent = file_get_contents($fullSourcePath);
            $proxyFileContent = str_replace(
                'require __DIR__ . \'/Scripts/typo3-console.php\';',
                '// In non Composer mode we\'re copied into TYPO3 web root
require __DIR__ . \'/typo3conf/ext/typo3_console/Scripts/typo3-console.php\';',
                $proxyFileContent
            );
            $success = file_put_contents($fullTargetPath, $proxyFileContent);
        }

        if ($success && !$this->isWindowsOs()) {
            $success = @chmod($fullTargetPath, 0755);
        }
        if ($success) {
            $success = @file_put_contents(
                $fullTargetPath,
                str_replace(
                    '{$relative-web-dir}',
                    $relativeWebDir,
                    file_get_contents($fullTargetPath)
                )
            );
        }

        return $success;
    }
private function safeCopy($fullSourcePath, $fullTargetPath, $relativeWebDir = '')
    {
        if (file_exists($fullTargetPath)) {
            if (!is_file($fullTargetPath)) {
                // Seems to be a directory: ignore
                return false;
            }
            if (!self::isTypo3CmsBinary($fullTargetPath)) {
                // File is there but does not seem to be a previous version of our script: better ignore
                return false;
            }
        }
        if ($this->isWindowsOs()) {
            $success = @copy($fullSourcePath, $fullTargetPath);
        } else {
            $proxyFileContent = file_get_contents($fullSourcePath);
            $proxyFileContent = str_replace(
                'require __DIR__ . \'/Scripts/typo3-console.php\';',
                '// In non Composer mode we\'re copied into TYPO3 web root
require __DIR__ . \'/typo3conf/ext/typo3_console/Scripts/typo3-console.php\';',
                $proxyFileContent
            );
            $success = file_put_contents($fullTargetPath, $proxyFileContent);
        }

        if ($success && !$this->isWindowsOs()) {
            $success = @chmod($fullTargetPath, 0755);
        }
        if ($success) {
            $success = @file_put_contents(
                $fullTargetPath,
                str_replace(
                    '{$relative-web-dir}',
                    $relativeWebDir,
                    file_get_contents($fullTargetPath)
                )
            );
        }

        return $success;
    }
Copy typo3 console binary to root directory taking several possible situations into account

@param string $fullSourcePath Path to the script that should be copied (depending on OS)
@param string $fullTargetPath Target path to which the script should be copied to
@param string $relativeWebDir Relative path to the web directory (which equals the TYPO3 root directory currently)
@return bool
@internal