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

Invalid cache directory when user name contains an umlaut #10434

Closed
gpoehl opened this issue Jan 5, 2022 · 22 comments
Closed

Invalid cache directory when user name contains an umlaut #10434

gpoehl opened this issue Jan 5, 2022 · 22 comments
Labels
Milestone

Comments

@gpoehl
Copy link

gpoehl commented Jan 5, 2022

After self-update to version 2.2.3 composer ignores existing umlaut in a user name.

EG: User name is Günter

Before the self update the directory
C:/Users/Günter/AppData/Local/Composer/files/
was used.
Now it is
C:/Users/Gnter/AppData/Local/Composer/files/

So it is not even posssible to rollback to the previous version.

@Seldaek
Copy link
Member

Seldaek commented Jan 5, 2022

You can do a fresh install with instructions from https://getcomposer.org/download/

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --version=2.1.14
php -r "unlink('composer-setup.php');"

Please check if 2.1.14 works, and ideally if you can check versions in between (2.2.0, 2.2.1, ..) to identify which one exactly broke this that would be great.

Can you also check what echo $Env:LOCALAPPDATA outputs in powershell, or try to get the value of that env var within whatever terminal you're using for Composer?

It'd be good to get more details, what env you are in, what error you see, etc.

@Seldaek Seldaek added the Bug label Jan 5, 2022
@Seldaek Seldaek added this to the 2.2 milestone Jan 5, 2022
@gpoehl
Copy link
Author

gpoehl commented Jan 6, 2022

I run the tests as mentioned.

Version 2.1.14 works fine.
echo $Env:LOCALAPPDATA outputs C:\Users\Günter\AppData\Local

The error comes with version 2.2.0. Message:
Cannot create cache directory C:/Users/Gnter/AppData/Local/Composer/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache

echo $Env:LOCALAPPDATA still outputs C:\Users\Günter\AppData\Local

My current php version is 8.0.7

@Seldaek
Copy link
Member

Seldaek commented Jan 6, 2022

OK could you check/share what php -r "var_dump($_SERVER['LOCALAPPDATA'] ?? 'unset', $_ENV['LOCALAPPDATA'] ?? 'unset', getenv('LOCALAPPDATA'));" outputs?

It's the only clue I have as to what would have caused a change here in 2.2 right now

@gpoehl
Copy link
Author

gpoehl commented Jan 6, 2022

The output is fine.

array(1) {
[0]=>
string(12) "LOCALAPPDATA"
}
array(1) {
[0]=>
string(12) "LOCALAPPDATA"
}
string(30) "C:\Users\Günter\AppData\Local"

@Seldaek
Copy link
Member

Seldaek commented Jan 6, 2022

Uhh those first two make no sense to me.. can you put this in a test.php file and run it from CLI?

<?php
var_dump($_SERVER['LOCALAPPDATA'] ?? 'unset', $_ENV['LOCALAPPDATA'] ?? 'unset', getenv('LOCALAPPDATA'));
php test.php

@gpoehl
Copy link
Author

gpoehl commented Jan 6, 2022

Now I'm surprised.

C:\Daten\WebRoot\test>php test.php
string(29) "C:\Users\Gnter\AppData\Local"
string(5) "unset"
string(30) "C:\Users\Günter\AppData\Local"

@Seldaek
Copy link
Member

Seldaek commented Jan 6, 2022

Ahh. OK so $_SERVER has the wrong info in it somehow, that makes sense as we started reading from $_SERVER as well as getenv in 2.2.. I wonder if that's a PHP bug then.

@Seldaek
Copy link
Member

Seldaek commented Jan 6, 2022

Can you try/check if you have default_charset = "utf-8" in php.ini?

@gpoehl
Copy link
Author

gpoehl commented Jan 6, 2022

It's in uppercase.
default_charset = "UTF-8"

@Seldaek
Copy link
Member

Seldaek commented Jan 6, 2022

In powershell I get this:

PS C:\Users\seld> $env:FOO = 'C:\Users\Günter'
PS C:\Users\seld> php .\test.php
string(15) "C:\Users\G�nter"
string(5) "unset"
string(16) "C:\Users\Günter"

cmd.exe too:

C:\Users\seld>set FOO=Günter

C:\Users\seld>php test.php
string(6) "G�nter"
string(5) "unset"
string(7) "Günter"

in bash/WSL it works fine though:

$ export FOO=Günter
$ php ~/test.php
/mnt/c/Users/seld/test.php:3:
string(7) "Günter"
/mnt/c/Users/seld/test.php:3:
string(5) "unset"
/mnt/c/Users/seld/test.php:3:
string(7) "Günter"

So it does appear to be a PHP-on-Windows bug. I filed a report on php/php-src#7896 - let's see if someone else has more of a clue. Otherwise I'll have to try and make a workaround in Composer.

@Seldaek Seldaek closed this as completed in 65c8daa Jan 7, 2022
@Seldaek
Copy link
Member

Seldaek commented Jan 7, 2022

@gpoehl please try again after a composer self-update --snapshot, hopefully it properly resolves it for you. Seems to work here but I only have an artificial test env..

@gpoehl
Copy link
Author

gpoehl commented Jan 7, 2022

@Seldaek ,
trying to install the snapshot fails. Error message:

[ErrorException]
file_put_contents(C:/Users/Gnter/AppData/Roaming/Composer/update-channel): Failed to open stream: No such file or
directory

Can I delete the globally installed version, then install version 2.1.14 and after this run the self-update --snapshot?

@Seldaek
Copy link
Member

Seldaek commented Jan 7, 2022

Yes sure that'll work

@gpoehl
Copy link
Author

gpoehl commented Jan 7, 2022

Sorry that I've come back with another question.
How can I install an old version? Installer installs version 2.2.3.
I managed to download a composer.phar file for version 2.1.14 but don't know how to install it.

@Seldaek
Copy link
Member

Seldaek commented Jan 7, 2022

See #10434 (comment) there's a --version flag for the composer-setup.php script. If you use the exe installer there's no way to do that I believe, you'd have to manually place the new phar file on top of wherever the exe installer installed the other phar.

@gpoehl
Copy link
Author

gpoehl commented Jan 7, 2022

I installed composer using the exe installer and replaced the composer.phar file within the 'programData\ComposerSetup\bin' directory. So I had a clean 2.1.14 version.
On this version running composer self-update --snapshot went well.

The snapshot itself solved the problem.
Thanks a lot.

@gpoehl
Copy link
Author

gpoehl commented Jan 7, 2022

@Seldaek ,
the problem hasn't been solved completely. Rollback still uses the wrong directory name.

C:>composer -V
Composer version 2.3-dev (2.3-dev+f1568f1f8f95686aa101452818d88f18225bc194) 2022-01-07 08:30:43

C:>composer self-update --rollback

In SelfUpdateCommand.php line 405:

Composer rollback failed: no installation to roll back to in "C:/Users/Gnter/AppData/Roaming/Composer"

self-update [-r|--rollback] [--clean-backups] [--no-progress] [--update-keys] [--stable] [--preview] [--snapshot] [--1] [--2] [--set-channel-only] [--] []

C:>composer -V
Composer version 2.3-dev (2.3-dev+f1568f1f8f95686aa101452818d88f18225bc194) 2022-01-07 08:30:43

@Seldaek
Copy link
Member

Seldaek commented Jan 7, 2022

OK that I cannot make any sense of :s

@johnstevenson
Copy link
Member

getenv() without the param returns the scrambled value, whereas getenv('name') doesn't.

@Seldaek
Copy link
Member

Seldaek commented Jan 7, 2022

Oh god.. I still had some other version of the workaround in my test file so I did not notice that 🤯

But then the snapshot did not fix anything at all.. Anyway fixing again, better

@Seldaek
Copy link
Member

Seldaek commented Jan 7, 2022

Alright @gpoehl please try again with d961998 and please verify that the snapshot really works because I think the previous one did not resolve anything at all, I'm not sure what made you believe it worked until you try the rollback.

@gpoehl
Copy link
Author

gpoehl commented Jan 8, 2022

I can confirm that version 2.2.4 solved the problem.

My previous assumtion, that your first fix alredy solved the problem, might have been wrong. It looks like that I run the tests in a powershell with administrator rights. The snapshot version created a new user in the user directory and run without providing an error message.
Again, thanks a lot.

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

3 participants