From 80826b96e20777d855a771536da9cd82ec3e2286 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Fri, 18 Nov 2011 10:48:48 +0000 Subject: [PATCH] Add protection against stowing into stow dirs --- stow.in | 2 ++ t/stow_contents.t | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/stow.in b/stow.in index 160e930..685774c 100755 --- a/stow.in +++ b/stow.in @@ -413,6 +413,8 @@ sub set_stow_path { sub stow_contents { my ($path, $target, $source) = @_; + return if should_skip_stow_dir_target($target); + my $cwd = getcwd(); my $msg = "Stowing contents of $path (cwd=$cwd, stow dir=$Stow_Path)"; $msg =~ s!$ENV{HOME}/!~/!g; diff --git a/t/stow_contents.t b/t/stow_contents.t index d589844..da0e5eb 100755 --- a/t/stow_contents.t +++ b/t/stow_contents.t @@ -7,7 +7,7 @@ # load as a library BEGIN { use lib qw(.); require "t/util.pm"; require "stow"; } -use Test::More tests => 14; +use Test::More tests => 16; use Test::Output; use English qw(-no_match_vars); @@ -276,3 +276,24 @@ ok( readlink('lib13/libb.so.1') eq '../../stow/pkg13b/lib13/libb.so.1' => '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" +);