Created
November 14, 2012 05:19
-
-
Save vovkasm/4070430 to your computer and use it in GitHub Desktop.
This may fix `perlbrew env` endless loop when some component in PERLBREW_ROOT is symlinks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/App/perlbrew.pm b/lib/App/perlbrew.pm | |
index 808a49f..c281399 100644 | |
--- a/lib/App/perlbrew.pm | |
+++ b/lib/App/perlbrew.pm | |
@@ -7,6 +7,7 @@ our $VERSION = "0.57"; | |
use Config; | |
use Capture::Tiny; | |
use Getopt::Long (); | |
+use Cwd 'realpath'; | |
use File::Spec::Functions qw( catfile catdir ); | |
use File::Basename; | |
use File::Path (); | |
@@ -202,6 +203,13 @@ sub installed_perl_executable { | |
return ""; | |
} | |
+sub installed_perl_prefix { | |
+ my ($self, $name) = @_; | |
+ my $prefix = realpath(catdir($self->root, "perls", $name)); | |
+ return $prefix if -e $prefix; | |
+ return ""; | |
+} | |
+ | |
sub cpan_mirror { | |
my ($self, $v) = @_; | |
unless($self->{cpan_mirror}) { | |
@@ -1454,19 +1462,12 @@ sub run_command_env { | |
if ($name) { | |
my($perl_name,$lib_name) = $self->resolve_installation_name($name); | |
- my $target_perl_executable = $self->installed_perl_executable($perl_name); | |
- | |
- my $link_count = 1; | |
- while (-l $target_perl_executable) { | |
- $target_perl_executable = readlink($target_perl_executable); | |
- $link_count++; | |
- if ($link_count++ > 100) { | |
- die "Problematic symlink detected: $target_perl_executable"; | |
- } | |
- } | |
+ my $target_perl_exe = $self->installed_perl_executable($perl_name); | |
+ | |
+ my $is_target_perl = $self->installed_perl_prefix($perl_name) eq realpath($Config{installprefix}); | |
- if ($target_perl_executable && $perl_name && $^X ne $target_perl_executable && -x $target_perl_executable && -x $0) { | |
- exec($target_perl_executable, $0, "env", $name); | |
+ if ($perl_name && $is_target_perl && -x $target_perl_exe && -x $0) { | |
+ exec($target_perl_exe, $0, "env", $name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment