2 namespace TYPO3\CMS\Composer\Plugin\Util;
27 foreach ($files as $file) {
28 if (!file_exists($file)) {
40 foreach ($files as $file) {
41 if (file_exists($file) || is_link($file)) {
53 public function establishSymlinks(array $links, $copyOnFailure = TRUE, $makeRelative = TRUE) {
54 foreach ($links as $source => $target) {
55 $this->
symlink($source, $target, $copyOnFailure, $makeRelative);
63 foreach ($links as $target) {
64 $this->
remove($target);
74 public function symlink($source, $target, $copyOnFailure = TRUE, $makeRelative = TRUE) {
75 if (!file_exists($source)) {
76 throw new \InvalidArgumentException(
'The symlink source "' . $source .
'" is not available.');
78 if (file_exists($target)) {
79 throw new \InvalidArgumentException(
'The symlink target "' . $target .
'" already exists.');
82 $symlinkSource = strtr($makeRelative ? $this->findShortestPath($target, $source) : $source,
'/', DIRECTORY_SEPARATOR);
83 $symlinkTarget = strtr($target,
'/', DIRECTORY_SEPARATOR);
84 $symlinkSuccessfull = @
symlink($symlinkSource, $symlinkTarget);
85 if (!$symlinkSuccessfull && !stristr(PHP_OS,
'darwin') && !stristr(PHP_OS,
'cygwin') && stristr(PHP_OS,
'win')) {
88 $parameter = is_dir($source) ?
' /D' :
'';
89 $processExecutor = new \Composer\Util\ProcessExecutor();
90 $symlinkSuccessfull = $processExecutor->execute(
'mklink' . $parameter .
' ' . escapeshellarg($symlinkTarget) .
' ' . escapeshellarg($symlinkSource), $output) === 0;
92 if (!$symlinkSuccessfull && !$copyOnFailure) {
93 throw new \RuntimeException(
'Symlinking target "' . $symlinkTarget .
'" to source "' . $symlinkSource .
'" ("' . $source .
'") failed.', 1430494084);
94 }
elseif (!$symlinkSuccessfull && $copyOnFailure) {
96 $this->
copy($symlinkSource, $symlinkTarget);
97 }
catch (\Exception $exception) {
98 throw new \RuntimeException(
'Neiter symlinking nor copying target "' . $symlinkTarget .
'" to source "' . $symlinkSource .
'" ("' . $source .
'") worked.', 1430494090);
109 public function copy($source, $target) {
110 if (!file_exists($source)) {
111 throw new \RuntimeException(
'The source "' . $source .
'" does not exist and cannot be copied.');
113 if (is_file($source)) {
114 $this->ensureDirectoryExists(dirname($target));
117 }
elseif (is_dir($source)) {
121 throw new \RuntimeException(
'The source "' . $source .
'" is neither a file nor a directory.');
129 $copySuccessful = @
copy($source, $target);
130 if (!$copySuccessful) {
131 throw new \RuntimeException(
'The source "' . $source .
'" could not be copied to target "' . $target .
'".');
140 $iterator = new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS);
141 $recursiveIterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
142 $this->ensureDirectoryExists($target);
144 foreach ($recursiveIterator as $file) {
145 $targetPath = $target . DIRECTORY_SEPARATOR . $recursiveIterator->getSubPathName();
146 if ($file->isDir()) {
147 $this->ensureDirectoryExists($targetPath);
149 $this->
copyFile($file->getPathname(), $targetPath);