Skip to content
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

"../.." is prepended to the path in the xml file after installation #259

Closed
shulard opened this issue May 18, 2020 · 6 comments
Closed

"../.." is prepended to the path in the xml file after installation #259

shulard opened this issue May 18, 2020 · 6 comments
Assignees
Labels

Comments

@shulard
Copy link

shulard commented May 18, 2020

Hello !

I'm currently using Phive in some projets and just encountered a strange behaviour.

My version:

Phive 0.14.1 - Copyright (C) 2015-2020 by Arne Blankerts, Sebastian Heuer and Contributors

Context

I just installed a phar using the simple install command :

phive install phpcs

This command results in the following XML configuration :

<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
  <phar name="phpcs" version="^3.5.5" installed="3.5.5" location="./tools/phpcs" copy="true"/>
</phive>

You can notice that there is a ^ before the version number. This character is familiar when using composer so I though that it means any version after 3.5.5 and before 3.6.0.

Problem

When I ran the phive install command after the XML was generated (for example on my CI environment), the XML get rewritten like this :

<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
  <phar name="phpcs" version="^3.5.5" installed="3.5.5" location="../.././tools/phpcs" copy="true"/>
</phive>

Each time I ran the phive install command it preprend ../.. before the location parameter.

Workaround

I found that if I remove the ^ I haven't any problem with the path update…

Is it a normal behaviour ? If it's a real issue, I can work on a PR to fix it.

@theseer
Copy link
Member

theseer commented May 18, 2020

Confirmed. And clearly a bug.

@theseer theseer self-assigned this May 18, 2020
@theseer theseer added the bug label May 18, 2020
@shulard
Copy link
Author

shulard commented May 18, 2020

Ok, let me try to fix it. I'm able to produce a PR tomorrow 😄.

@theseer
Copy link
Member

theseer commented May 18, 2020

<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
  <phar name="phpcs" version="^3.5.5" installed="3.5.5" location="./tools/phpcs" copy="true"/>
</phive>

You can notice that there is a ^ before the version number. This character is familiar when using composer so I though that it means any version after 3.5.5 and before 3.6.0.

Correct. We try to behave as closely as possible the way composer works when it comes to version constraints itself. Given that you can, as you did, install a phar without specifying a version, we prepend it with ^ to be semantically save yet allow for updating.

<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
  <phar name="phpcs" version="^3.5.5" installed="3.5.5" location="../.././tools/phpcs" copy="true"/>
</phive>

Each time I ran the phive install command it preprend ../.. before the location parameter.

Workaround

I found that if I remove the ^ I haven't any problem with the path update…

That is weird, as that should not have any logical relation.

Is it a normal behaviour ? If it's a real issue, I can work on a PR to fix it.

No, certainly not normal behavior.
I'll have a look.

@shulard
Copy link
Author

shulard commented May 18, 2020

I just checked and it seems related to the phar.io/filesystem package and the Directory::getRelativePathTo method.

Because my app installation path is /app and the location in the XML configuration is ./tools/phpcs it as trouble finding the relative path between /app and ./tools.

A workaround seems to use the realpath function in the Directory constructor to be sure that the path is always a full path to compare.

@theseer
Copy link
Member

theseer commented May 18, 2020

Realpath will also resolve symbolic links. That's not helpful in this case.

@theseer
Copy link
Member

theseer commented May 18, 2020

You're right about the relativePath resolving though. By default we prepend the working directory to the "tools" path, somehow this gets mangled when receiving the path from the registry.

@theseer theseer changed the title When version starts with ^, "../.." is prepended to the path in the xml file after installation succeeded. "../.." is prepended to the path in the xml file after installation May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants