Add protection against stowing into stow dirs

This commit is contained in:
Adam Spiers 2011-11-18 10:48:48 +00:00
parent 89b7de8c04
commit 80826b96e2
2 changed files with 24 additions and 1 deletions

View file

@ -413,6 +413,8 @@ sub set_stow_path {
sub stow_contents { sub stow_contents {
my ($path, $target, $source) = @_; my ($path, $target, $source) = @_;
return if should_skip_stow_dir_target($target);
my $cwd = getcwd(); my $cwd = getcwd();
my $msg = "Stowing contents of $path (cwd=$cwd, stow dir=$Stow_Path)"; my $msg = "Stowing contents of $path (cwd=$cwd, stow dir=$Stow_Path)";
$msg =~ s!$ENV{HOME}/!~/!g; $msg =~ s!$ENV{HOME}/!~/!g;

View file

@ -7,7 +7,7 @@
# load as a library # load as a library
BEGIN { use lib qw(.); require "t/util.pm"; require "stow"; } BEGIN { use lib qw(.); require "t/util.pm"; require "stow"; }
use Test::More tests => 14; use Test::More tests => 16;
use Test::Output; use Test::Output;
use English qw(-no_match_vars); use English qw(-no_match_vars);
@ -276,3 +276,24 @@ ok(
readlink('lib13/libb.so.1') eq '../../stow/pkg13b/lib13/libb.so.1' readlink('lib13/libb.so.1') eq '../../stow/pkg13b/lib13/libb.so.1'
=> 'unfolding to stow links to libraries' => 'unfolding to stow links to libraries'
); );
#
# stowing to stow dir should fail
#
reset_state();
$Stow_Path= 'stow';
make_dir('stow/pkg14/stow/pkg15');
make_file('stow/pkg14/stow/pkg15/node15');
stow_contents('stow/pkg14', '.', 'stow/pkg14');
stderr_like(
sub { process_tasks(); },
qr/There are no outstanding operations to perform/,
'no tasks to process'
);
ok(
scalar(@Conflicts) == 0 &&
! -l 'stow/pkg15'
=> "stowing to stow dir should fail"
);