10000 [2.1] Fixed "assets:install" to create relative instead of absolute symlinks by ericclemmons · Pull Request #1173 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[2.1] Fixed "assets:install" to create relative instead of absolute symlinks #1173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,48 @@ protected function execute(InputInterface $input, OutputInterface $output)

foreach ($this->container->get('kernel')->getBundles() as $bundle) {
if (is_dir($originDir = $bundle->getPath().'/Resources/public')) {
$targetDir = $input->getArgument('target').'/bundles/'.preg_replace('/bundle$/', '', strtolower($bundle->getName()));
$bundlesDir = $input->getArgument('target').'/bundles/';
$targetDir = $bundlesDir.preg_replace('/bundle$/', '', strtolower($bundle->getName 8000 ()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing this ? You add a variable used only on the next line which is useless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line #85 uses it as well.

I added it so the function call to makePathRelative wouldn't require duplicate concatenation: realpath($input->getArgument('target').'/bundles/')


$output->writeln(sprintf('Installing assets for <comment>%s</comment> into <comment>%s</comment>', $bundle->getNamespace(), $targetDir));

$filesystem->remove($targetDir);

if ($input->getOption('symlink')) {
$filesystem->symlink($originDir, $targetDir);
$relativeOriginDir = $this->makePathRelative($originDir, realpath($bundlesDir));
$filesystem->symlink($relativeOriginDir, $targetDir);
} else {
$filesystem->mkdir($targetDir, 0777);
$filesystem->mirror($originDir, $targetDir);
}
}
}
}

/**
* Given an existing path, convert it to a path relative to a given starting path
*
* @var string Absolute path of target
* @var string Absolute path where traversal begins
* @return string Path of target relative to starting path
*/
protected function makePathRelative($endPath, $startPath)
{
// Find for which character the the common path stops
$offset = 0;
while ($startPath[$offset] === $endPath[$offset]) {
$offset++;
}

// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
$depth = substr_count(substr($startPath, $offset), DIRECTORY_SEPARATOR) + 1;

// Repeated "../" for each level need to reach the common path
$traverser = str_repeat('../', $depth);

// Construct $endPath from traversing to the common path, then to the remaining $endPath
$relativePath = $traverser.substr($endPath, $offset);

return $relativePath;
}
}
0