Skip to content

Commit

Permalink
Fix bug where PKGDEST in makepkg.conf needs shell expansion.
Browse files Browse the repository at this point in the history
- Environment variables and tildes are expanded
- Backslashes (escapes) are removed in a fairly dumb way.
  • Loading branch information
juster committed Feb 18, 2010
1 parent db36f6f commit 5473705
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
@@ -1,3 +1,11 @@
2010-02-21 Justin Davis <juster@cpan.org>

* lib/CPANPLUS/Dist/Arch.pm (_shell_expand): Created helper
function for reading PKGDEST from /etc/makepkg.conf entries.
Fixed bug when PKGDEST in makepkg.conf contains environment
variables or tildes that need shell expansion.
Reported by Isaac Good

2010-02-18 Justin Davis <juster@cpan.org>

* lib/CPANPLUS/Dist/Arch.pm (get_pkgname): Added method.
Expand Down
24 changes: 17 additions & 7 deletions lib/CPANPLUS/Dist/Arch.pm
Expand Up @@ -129,6 +129,20 @@ our ($Is_dependency, $PKGDEST, $PACKAGER);

$PACKAGER = 'Anonymous';

#---HELPER FUNCTION---
# Purpose: Expand environment variables and tildes like bash would.
#---------------------
sub _shell_expand
{
my $dir = shift;
$dir =~ s/ \A ~ / $ENV{HOME} /xmse; # tilde = homedir
$dir =~ s/ (?<!\\) \$ (\w+) / $ENV{$1} || q{} /xmseg; # expand env vars
$dir =~ s/ \\ [a-zA-Z] / /xmsg;
$dir =~ s/ \\ (.) / $1 /xmsg; # escaped special
# chars
return $dir;
}

READ_CONF:
{
# Read makepkg.conf to see if there are system-wide settings
Expand All @@ -151,13 +165,9 @@ READ_CONF:
( $value =~ m/\A"(.*)"\z/ ?
do {
$value = $1;
$value =~ tr/\\//d;
$value;
} :

$value =~ m/\A'(.*)'\z/ ? $1 :

$value );
_shell_expand( $1 )
} : ( $value =~ m/\A'(.*)'\z/ ? $1 : # dont expand ''s
_shell_expand( $value )));
}
}
close $mkpkgconf or error "close on makepkg.conf: $!";
Expand Down

0 comments on commit 5473705

Please sign in to comment.