Search code examples
perlpathcpanm

cpanm self-upgrade choking due Windows style 8.3 format path to site/bin


PS> cpanm --self-upgrade
You are running cpanm from the path where your current perl won't install executables to.
Because of that, cpanm --self-upgrade won't upgrade the version of cpanm you're running.

  cpanm path   : C:\Programs\Strawberry\perl\site\bin\cpanm.bat
  Install path : C:\Programs\STRAWB~1\perl\site\bin

It means you either installed cpanm globally with system perl, or use distro packages such
as rpm or apt-get, and you have to use them again to upgrade cpanm.

How do I either (a) make cpanm understand that these are the same paths, or (b) change the configured executable-installation path of Perl?


Solution

  • Instead of cpanm --self-upgrade, simply doing it as cpanm App::cpanminus did the trick. (There was an error that cpanm.bat.AAA could not be renamed into cpanm.bat, and that it would be renamed at next boot, but I just renamed it manually.)


    And to prevent potential other problems similar to this, I moved Perl to under C:\Programs\berry\ (just to keep it under 8 letters), and edited lib/CPAN/Config.pm, lib/Config_heavy.pl, lib/Config.pm to replace STRAWB~1 with berry in every path.
    (The last two files here are as suggested by an answer in http://www.perlmonks.org/?node_id=680994 , and the first one is from cpan's output during o conf. )

    This path change unfortunately doesn't help with making cpanm's --self-upgrade work though, as it prints the same error message as in the question, with these shown as the differing paths now:

    cpanm path   : C:\Programs\berry\perl\site\bin\cpanm.bat
    Install path : C:\Programs\berry\perl\site\bin
    

    Huh? Aren't they the same paths? Well, line 634 of https://metacpan.org/source/MIYAGAWA/App-cpanminus-1.7039/lib/App/cpanminus/fatscript.pm seems to be where this check is happening, and that line is assuming the $install_base won't contain special characters - but the backslashes in Windows paths are seen as special characters by Perl. So, Perl sees weird characters in the Install path that are different from the cpanm path, and declares it a non-match.
    Changing the regex match there to /\Q$install_base\E/ would fix this, but an immediate solution as an end user is the cpanm App::cpanminus one at the top.