phar-io / phive

The Phar Installation and Verification Environment (PHIVE)
https://phar.io
BSD 3-Clause "New" or "Revised" License
579 stars 43 forks source link

symlink(): Protocol error #169

Open NavyCoat opened 5 years ago

NavyCoat commented 5 years ago

There was nice message to report bug, so...

it's occured on newly installed (5 min ago) phive, when i'm trying to run phive install phpab

Phive 0.12.0 - Copyright (C) 2015-2018 by Arne Blankerts, Sebastian Heuer and Contributors
Fetching repository list
Downloading https://phar.io/data/repositories.xml
Downloading https://api.github.com/repos/theseer/autoload/releases
Downloading https://github.com/theseer/Autoload/releases/download/1.25.0/phpab-1.25.0.phar
Downloading https://github.com/theseer/Autoload/releases/download/1.25.0/phpab-1.25.0.phar.asc
Downloading key 2A8299CE842DD38C
Trying hkps.pool.sks-keyservers.net (5.9.137.111)
Downloading https://hkps.pool.sks-keyservers.net/pks/lookup?search=0x2A8299CE842DD38C&op=index&options=mr
Downloading https://hkps.pool.sks-keyservers.net/pks/lookup?search=0x2A8299CE842DD38C&op=get&options=mr
Successfully downloaded key

        Fingerprint: BEEB 9AED 51C2 8445 FAB1 4222 8DDB 46C4 EA2E BCDC

        Arne Blankerts <Arne@Blankerts.de> (2015-09-23)
        Arne Blankerts (Keybase.io) <theseer@keybase.io> (2015-09-23)

        Created: 2009-03-14

Import this key? [y|N] y
Linking /home/vagrant/.phive/phars/phpab-1.25.0.phar to /workspace/tools/phpab
[ERROR]    An error occurred while processing your request:

          symlink(): Protocol error

          #0 har:///usr/local/bin/phive/src/services/phar/UnixoidPharInstaller.php(13)
          #1 unknown file(0): PharIo\Phive\Cli\Runner->errorHandler()
          #2 har:///usr/local/bin/phive/src/services/phar/UnixoidPharInstaller.php(13): symlink()
          #3 har:///usr/local/bin/phive/src/services/phar/PharInstaller.php(37): PharIo\Phive\UnixoidPharInstaller->link()
          #4 har:///usr/local/bin/phive/src/services/phar/InstallService.php(73): PharIo\Phive\PharInstaller->install()
          #5 har:///usr/local/bin/phive/src/commands/install/InstallCommand.php(63): PharIo\Phive\InstallService->execute()
          #6 har:///usr/local/bin/phive/src/commands/install/InstallCommand.php(51): PharIo\Phive\InstallCommand->installRequestedPhar()
          #7 har:///usr/local/bin/phive/src/shared/cli/Runner.php(211): PharIo\Phive\InstallCommand->execute()
          #8 har:///usr/local/bin/phive/src/shared/cli/Runner.php(70): PharIo\Phive\Cli\Runner->execute()
          #9 usr/local/bin/phive(306): PharIo\Phive\Cli\Runner->run()
          #10 {main}

          Environment: PHP 7.1.18-1+ubuntu16.04.1+deb.sury.org+1
          Phive Version: 0.12.0

          This should not have happened and is most likely a bug.
          Please report it at https://github.com/phar-io/phive/issues, make sure you include
          the full output of this error message. Thank you!
theseer commented 5 years ago

This seems to be a problem specific to vagrant/virtualbox on a windows host with a linux guest and shared folders.

I found a similar issue that existed for npm (https://github.com/npm/npm/issues/12733). Some further google foo directed me to an article at http://perrymitchell.net/article/npm-symlinks-through-vagrant-windows/, which seems to address that issue. Admittingly the post is quite old - it's from 2015 - and may no longer be relevant or the way to go.

@ThomasWeinert Any chance you can have a look into that?

theseer commented 5 years ago

We certainly need to not crash here, so have to handle a failing symlink call properly.

I'm not sure though as to what the correct fix for the actual problem would be?

filips123 commented 5 years ago

Virtualbox does not allow symlinks on shared folders for security reasons. They need to be enabled seperatly. See https://stackoverflow.com/a/24365338/6523409

Phive should detect if symlinks are not supported and then copy file instead of make symlink. MAybe it could detect this by making test symlink and check if there is no error.

theseer commented 5 years ago

Phive should detect if symlinks are not supported and then copy file instead of make symlink.

That doesn't work: To the best of my knowledge, there is no API, neither in PHP nor on a lower level, to learn whether or not symlinks are supported on the given target directory. And that makes sense as given the tree structure of a unix system, you'd have to read the fstab along with realpath resovling to figure out on what FS the given target ends up on. Once you know the FS type you might have to either just know or find out by other means if symlinks are supported by it. Given that the behavior might even change based on configuration of the FS, that's rather unreliable.

The only workaround for that might be to try to just attempt to create a symlink and see if that fails. It could fail for various reasons though...

Additionally, silently creating a copy instead is unexpected behavior. We could of course add some output to make it not "silent" but who reads output? ;)

So far, I'm considering to simply fail the install.