8000 Fix support for symlinks on Windows. by david-garcia-garcia · Pull Request #6213 · composer/composer · GitHub
[go: up one dir, main page]

Skip to content

Fix support for symlinks on Windows. #6213

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

Closed

Conversation

david-garcia-garcia
Copy link

Fix for discussion on:

#6174

The symlink function from PHP in Windows is totally broken when using relative paths. This pull requests uses several fallback mechanisms before using a junction.

The problems with junctions is that they are not portable, making artifacts built with composer unusable for deployments.

@@ -76,40 +79,79 @@ public function download(PackageInterface $package, $path, $output = true)
$this->filesystem->removeDirectory($path);

if ($output) {
$this->io->writeError(sprintf(
$this->io->write(sprintf(
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a no-go. Feedback given to humans goes to the second pipe (named STDERR in PHP), not the first one

Choose a reason for hiding this comment

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

Fixed. Had no clue... having "error" there was really confusing me.

$this->io->writeError(sprintf(' Symlinked from %s', $url), false);
$linked = true;
}
catch (IOException $e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should be on the previous line

Choose a reason for hiding this comment

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

Fixed. My IDE is using coding standards from other projects...

if (!$linked && Platform::isWindows()) {
// Use command linke symlinking as a fallback.
try {
$return_var = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should use camelCase.

And you don't need to initialize it here, as it is a by-ref variable.

And $exitCode is a better name for what it does

Choose a reason for hiding this comment

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

return_var is from PHP's exec documentation itself.

By ref does not guarantee that these variables are really set in the callee. I only do that to get the IDE to give them a type automatically. Should do no harm.

Copy link
Member

Choose a reason for hiding this comment

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

The name $return_var is up to you entirely, it's just an example in the docs. The function will set the value by ref no matter what the variable is called.

Copy link
Author

Choose a reason for hiding this comment

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

The function will set the value by ref no matter what the variable is called.

Sure. It was just a mater of consistency. Whatever, already changed it.

@david-garcia-garcia
Copy link
Author

Just as a final thought. Even though this patch fixes symlinks on Windows, I would NOT recommend at all their usage.

I.e. if you copy a symlink using the windows explorer, it will be ignored and copied as an empty folder. Or some tools (such as AppVeyor's artifact packages) will create Zip's where the files are duplicated and the symlinks removed.

All-in-all, the best approach is to have composer use the packages in their original local path:

#6174

@curry684
Copy link
Contributor
curry684 commented Mar 3, 2017

The problems with junctions is that they are not portable, making artifacts built with composer unusable for deployments.

I'm not really sure what issue you are describing with this, but the simple solution would just be to disable symlinking when building cross-platform artifacts.

@david-garcia-garcia
Copy link
Author

I'm not really sure what issue you are describing with this, but the simple solution would just be to disable symlinking when building cross-platform artifacts.

With "portable" I am not talking about moving this from windows to linux (or the other way round). I mean that Junctions always use absolute paths. So if I build an artifact using composer on one machine, CI system, whatever, then I will only be able to use it on another system that has exactly the same folder structure. It cannot be moved around. Plus all the other issues with symlinks themselves.

the simple solution would just be to disable symlinking when building cross-platform artifacts.

This means that these artifacts will have duplicate code, not a big deal, but can be an issue on big projects.

}

if (!$linked && Platform::isWindows()) {
// Use command linke symlinking as a fallback.
Copy link
Member

Choose a reason for hiding this comment

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

s/linke/line/

@Seldaek
Copy link
Member
Seldaek commented Mar 6, 2017

As far as I understand, this doesn't fix much as symlinks or junctions are equally broken, and symlinks are generally not working anyway since most people don't run elevated shells, so I'd rather not merge it and risk a regression if it's not improving things much. If I'm mistaken let me know and we can revisit the issue.

@Seldaek Seldaek closed this Mar 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0