make it more obvious when target (sub)directory is skipped
This should avoid the sort of confusion seen in: https://github.com/aspiers/shell-env/issues/1
This commit is contained in:
parent
497a067621
commit
07a84541f1
5 changed files with 65 additions and 5 deletions
|
@ -550,12 +550,12 @@ sub should_skip_target_which_is_stow_dir {
|
||||||
|
|
||||||
# Don't try to remove anything under a stow directory
|
# Don't try to remove anything under a stow directory
|
||||||
if ($target eq $self->{stow_path}) {
|
if ($target eq $self->{stow_path}) {
|
||||||
debug(2, "Skipping target which was current stow directory $target");
|
warn "WARNING: skipping target which was current stow directory $target\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($self->marked_stow_dir($target)) {
|
if ($self->marked_stow_dir($target)) {
|
||||||
debug(2, "Skipping protected directory $target");
|
warn "WARNING: skipping protected directory $target\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
t/stow.t
7
t/stow.t
|
@ -7,7 +7,7 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Test::More tests => 111;
|
use Test::More tests => 112;
|
||||||
use Test::Output;
|
use Test::Output;
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
|
|
||||||
|
@ -368,6 +368,7 @@ $stow = new_Stow(dir => 'stow');
|
||||||
make_dir('stow/pkg14/stow/pkg15');
|
make_dir('stow/pkg14/stow/pkg15');
|
||||||
make_file('stow/pkg14/stow/pkg15/node15');
|
make_file('stow/pkg14/stow/pkg15/node15');
|
||||||
|
|
||||||
|
capture_stderr();
|
||||||
$stow->plan_stow('pkg14');
|
$stow->plan_stow('pkg14');
|
||||||
is($stow->get_tasks, 0, 'no tasks to process');
|
is($stow->get_tasks, 0, 'no tasks to process');
|
||||||
ok(
|
ok(
|
||||||
|
@ -375,6 +376,10 @@ ok(
|
||||||
! -l 'stow/pkg15'
|
! -l 'stow/pkg15'
|
||||||
=> "stowing to stow dir should fail"
|
=> "stowing to stow dir should fail"
|
||||||
);
|
);
|
||||||
|
like($stderr,
|
||||||
|
qr/WARNING: skipping target which was current stow directory stow/
|
||||||
|
=> "stowing to stow dir should give warning");
|
||||||
|
uncapture_stderr();
|
||||||
|
|
||||||
#
|
#
|
||||||
# stow a simple tree minimally when cwd isn't target
|
# stow a simple tree minimally when cwd isn't target
|
||||||
|
|
|
@ -13,6 +13,7 @@ use Carp qw(croak);
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
use File::Path qw(remove_tree);
|
use File::Path qw(remove_tree);
|
||||||
use File::Spec;
|
use File::Spec;
|
||||||
|
use IO::Scalar;
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
|
||||||
use Stow;
|
use Stow;
|
||||||
|
@ -21,6 +22,7 @@ use Stow::Util qw(parent canon_path);
|
||||||
use base qw(Exporter);
|
use base qw(Exporter);
|
||||||
our @EXPORT = qw(
|
our @EXPORT = qw(
|
||||||
$OUT_DIR
|
$OUT_DIR
|
||||||
|
$stderr
|
||||||
init_test_dirs
|
init_test_dirs
|
||||||
cd
|
cd
|
||||||
new_Stow new_compat_Stow
|
new_Stow new_compat_Stow
|
||||||
|
@ -28,10 +30,24 @@ our @EXPORT = qw(
|
||||||
remove_dir remove_link
|
remove_dir remove_link
|
||||||
cat_file
|
cat_file
|
||||||
is_link is_dir_not_symlink is_nonexistent_path
|
is_link is_dir_not_symlink is_nonexistent_path
|
||||||
|
capture_stderr uncapture_stderr
|
||||||
);
|
);
|
||||||
|
|
||||||
our $OUT_DIR = 'tmp-testing-trees';
|
our $OUT_DIR = 'tmp-testing-trees';
|
||||||
|
|
||||||
|
our $stderr;
|
||||||
|
my $tied_err;
|
||||||
|
|
||||||
|
sub capture_stderr {
|
||||||
|
undef $stderr;
|
||||||
|
$tied_err = tie *STDERR, 'IO::Scalar', \$stderr;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub uncapture_stderr {
|
||||||
|
undef $tied_err;
|
||||||
|
untie *STDERR;
|
||||||
|
}
|
||||||
|
|
||||||
sub init_test_dirs {
|
sub init_test_dirs {
|
||||||
for my $dir ("$OUT_DIR/target", "$OUT_DIR/stow") {
|
for my $dir ("$OUT_DIR/target", "$OUT_DIR/stow") {
|
||||||
-d $dir and remove_tree($dir);
|
-d $dir and remove_tree($dir);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Test::More tests => 38;
|
use Test::More tests => 39;
|
||||||
use Test::Output;
|
use Test::Output;
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
|
|
||||||
|
@ -154,6 +154,7 @@ ok(
|
||||||
=> q(don't unlink any nodes under the stow directory)
|
=> q(don't unlink any nodes under the stow directory)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Don't unlink any nodes under another stow directory
|
# Don't unlink any nodes under another stow directory
|
||||||
#
|
#
|
||||||
|
@ -167,6 +168,7 @@ make_dir('stow/pkg8a/stow2/pkg8b');
|
||||||
make_file('stow/pkg8a/stow2/pkg8b/file8b');
|
make_file('stow/pkg8a/stow2/pkg8b/file8b');
|
||||||
make_link('stow2/pkg8b', '../stow/pkg8a/stow2/pkg8b');
|
make_link('stow2/pkg8b', '../stow/pkg8a/stow2/pkg8b');
|
||||||
|
|
||||||
|
capture_stderr();
|
||||||
$stow->plan_unstow('pkg8a');
|
$stow->plan_unstow('pkg8a');
|
||||||
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg8a');
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg8a');
|
||||||
ok(
|
ok(
|
||||||
|
@ -175,6 +177,10 @@ ok(
|
||||||
readlink('stow2/pkg8b') eq '../stow/pkg8a/stow2/pkg8b'
|
readlink('stow2/pkg8b') eq '../stow/pkg8a/stow2/pkg8b'
|
||||||
=> q(don't unlink any nodes under another stow directory)
|
=> q(don't unlink any nodes under another stow directory)
|
||||||
);
|
);
|
||||||
|
like($stderr,
|
||||||
|
qr/WARNING: skipping protected directory stow2/
|
||||||
|
=> "unstowing from ourself should skip stow");
|
||||||
|
uncapture_stderr();
|
||||||
|
|
||||||
#
|
#
|
||||||
# overriding already stowed documentation
|
# overriding already stowed documentation
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Test::More tests => 23;
|
use Test::More tests => 37;
|
||||||
use Test::Output;
|
use Test::Output;
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
|
|
||||||
|
@ -151,6 +151,7 @@ make_dir('stow/pkg7a/stow/pkg7b');
|
||||||
make_file('stow/pkg7a/stow/pkg7b/file7b');
|
make_file('stow/pkg7a/stow/pkg7b/file7b');
|
||||||
make_link('stow/pkg7b', '../stow/pkg7a/stow/pkg7b');
|
make_link('stow/pkg7b', '../stow/pkg7a/stow/pkg7b');
|
||||||
|
|
||||||
|
capture_stderr();
|
||||||
$stow->plan_unstow('pkg7b');
|
$stow->plan_unstow('pkg7b');
|
||||||
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg7b');
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg7b');
|
||||||
ok(
|
ok(
|
||||||
|
@ -159,6 +160,10 @@ ok(
|
||||||
readlink('stow/pkg7b') eq '../stow/pkg7a/stow/pkg7b'
|
readlink('stow/pkg7b') eq '../stow/pkg7a/stow/pkg7b'
|
||||||
=> q(don't unlink any nodes under the stow directory)
|
=> q(don't unlink any nodes under the stow directory)
|
||||||
);
|
);
|
||||||
|
like($stderr,
|
||||||
|
qr/WARNING: skipping target which was current stow directory stow/
|
||||||
|
=> "warn when unstowing from ourself");
|
||||||
|
uncapture_stderr();
|
||||||
|
|
||||||
#
|
#
|
||||||
# Don't unlink any nodes under another stow directory
|
# Don't unlink any nodes under another stow directory
|
||||||
|
@ -173,6 +178,7 @@ make_dir('stow/pkg8a/stow2/pkg8b');
|
||||||
make_file('stow/pkg8a/stow2/pkg8b/file8b');
|
make_file('stow/pkg8a/stow2/pkg8b/file8b');
|
||||||
make_link('stow2/pkg8b', '../stow/pkg8a/stow2/pkg8b');
|
make_link('stow2/pkg8b', '../stow/pkg8a/stow2/pkg8b');
|
||||||
|
|
||||||
|
capture_stderr();
|
||||||
$stow->plan_unstow('pkg8a');
|
$stow->plan_unstow('pkg8a');
|
||||||
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg8a');
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg8a');
|
||||||
ok(
|
ok(
|
||||||
|
@ -181,10 +187,25 @@ ok(
|
||||||
readlink('stow2/pkg8b') eq '../stow/pkg8a/stow2/pkg8b'
|
readlink('stow2/pkg8b') eq '../stow/pkg8a/stow2/pkg8b'
|
||||||
=> q(don't unlink any nodes under another stow directory)
|
=> q(don't unlink any nodes under another stow directory)
|
||||||
);
|
);
|
||||||
|
like($stderr,
|
||||||
|
qr/WARNING: skipping target which was current stow directory stow/
|
||||||
|
=> "warn when skipping unstowing");
|
||||||
|
uncapture_stderr();
|
||||||
|
|
||||||
#
|
#
|
||||||
# overriding already stowed documentation
|
# overriding already stowed documentation
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# This will be used by this and subsequent tests
|
||||||
|
sub check_protected_dirs_skipped {
|
||||||
|
for my $dir (qw{stow stow2}) {
|
||||||
|
like($stderr,
|
||||||
|
qr/WARNING: skipping protected directory $dir/
|
||||||
|
=> "warn when skipping protected directory $dir");
|
||||||
|
}
|
||||||
|
uncapture_stderr();
|
||||||
|
}
|
||||||
|
|
||||||
$stow = new_compat_Stow(override => ['man9', 'info9']);
|
$stow = new_compat_Stow(override => ['man9', 'info9']);
|
||||||
make_file('stow/.stow');
|
make_file('stow/.stow');
|
||||||
|
|
||||||
|
@ -195,6 +216,7 @@ make_link('man9/man1/file9.1' => '../../../stow/pkg9a/man9/man1/file9.1'); # emu
|
||||||
|
|
||||||
make_dir('../stow/pkg9b/man9/man1');
|
make_dir('../stow/pkg9b/man9/man1');
|
||||||
make_file('../stow/pkg9b/man9/man1/file9.1');
|
make_file('../stow/pkg9b/man9/man1/file9.1');
|
||||||
|
capture_stderr();
|
||||||
$stow->plan_unstow('pkg9b');
|
$stow->plan_unstow('pkg9b');
|
||||||
$stow->process_tasks();
|
$stow->process_tasks();
|
||||||
ok(
|
ok(
|
||||||
|
@ -202,6 +224,7 @@ ok(
|
||||||
!-l 'man9/man1/file9.1'
|
!-l 'man9/man1/file9.1'
|
||||||
=> 'overriding existing documentation files'
|
=> 'overriding existing documentation files'
|
||||||
);
|
);
|
||||||
|
check_protected_dirs_skipped();
|
||||||
|
|
||||||
#
|
#
|
||||||
# deferring to already stowed documentation
|
# deferring to already stowed documentation
|
||||||
|
@ -221,6 +244,7 @@ make_link('man10/man1/file10b.1' => '../../../stow/pkg10b/man10/man1/file10b.1'
|
||||||
|
|
||||||
make_dir('../stow/pkg10c/man10/man1');
|
make_dir('../stow/pkg10c/man10/man1');
|
||||||
make_file('../stow/pkg10c/man10/man1/file10a.1');
|
make_file('../stow/pkg10c/man10/man1/file10a.1');
|
||||||
|
capture_stderr();
|
||||||
$stow->plan_unstow('pkg10c');
|
$stow->plan_unstow('pkg10c');
|
||||||
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg10c');
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg10c');
|
||||||
ok(
|
ok(
|
||||||
|
@ -228,6 +252,7 @@ ok(
|
||||||
readlink('man10/man1/file10a.1') eq '../../../stow/pkg10a/man10/man1/file10a.1'
|
readlink('man10/man1/file10a.1') eq '../../../stow/pkg10a/man10/man1/file10a.1'
|
||||||
=> 'defer to existing documentation files'
|
=> 'defer to existing documentation files'
|
||||||
);
|
);
|
||||||
|
check_protected_dirs_skipped();
|
||||||
|
|
||||||
#
|
#
|
||||||
# Ignore temp files
|
# Ignore temp files
|
||||||
|
@ -241,6 +266,7 @@ make_file('../stow/pkg12/man12/man1/.#file12.1');
|
||||||
make_dir('man12/man1');
|
make_dir('man12/man1');
|
||||||
make_link('man12/man1/file12.1' => '../../../stow/pkg12/man12/man1/file12.1');
|
make_link('man12/man1/file12.1' => '../../../stow/pkg12/man12/man1/file12.1');
|
||||||
|
|
||||||
|
capture_stderr();
|
||||||
$stow->plan_unstow('pkg12');
|
$stow->plan_unstow('pkg12');
|
||||||
$stow->process_tasks();
|
$stow->process_tasks();
|
||||||
ok(
|
ok(
|
||||||
|
@ -248,17 +274,20 @@ ok(
|
||||||
!-e 'man12/man1/file12.1'
|
!-e 'man12/man1/file12.1'
|
||||||
=> 'ignore temp files'
|
=> 'ignore temp files'
|
||||||
);
|
);
|
||||||
|
check_protected_dirs_skipped();
|
||||||
|
|
||||||
#
|
#
|
||||||
# Unstow an already unstowed package
|
# Unstow an already unstowed package
|
||||||
#
|
#
|
||||||
$stow = new_compat_Stow();
|
$stow = new_compat_Stow();
|
||||||
|
capture_stderr();
|
||||||
$stow->plan_unstow('pkg12');
|
$stow->plan_unstow('pkg12');
|
||||||
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg12');
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg12');
|
||||||
ok(
|
ok(
|
||||||
$stow->get_conflict_count == 0
|
$stow->get_conflict_count == 0
|
||||||
=> 'unstow already unstowed package pkg12'
|
=> 'unstow already unstowed package pkg12'
|
||||||
);
|
);
|
||||||
|
check_protected_dirs_skipped();
|
||||||
|
|
||||||
#
|
#
|
||||||
# Unstow a never stowed package
|
# Unstow a never stowed package
|
||||||
|
@ -268,12 +297,14 @@ eval { remove_dir("$OUT_DIR/target"); };
|
||||||
mkdir("$OUT_DIR/target");
|
mkdir("$OUT_DIR/target");
|
||||||
|
|
||||||
$stow = new_compat_Stow();
|
$stow = new_compat_Stow();
|
||||||
|
capture_stderr();
|
||||||
$stow->plan_unstow('pkg12');
|
$stow->plan_unstow('pkg12');
|
||||||
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg12 which was never stowed');
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg12 which was never stowed');
|
||||||
ok(
|
ok(
|
||||||
$stow->get_conflict_count == 0
|
$stow->get_conflict_count == 0
|
||||||
=> 'unstow never stowed package pkg12'
|
=> 'unstow never stowed package pkg12'
|
||||||
);
|
);
|
||||||
|
check_protected_dirs_skipped();
|
||||||
|
|
||||||
#
|
#
|
||||||
# Unstowing when target contains a real file shouldn't be an issue.
|
# Unstowing when target contains a real file shouldn't be an issue.
|
||||||
|
@ -281,6 +312,7 @@ ok(
|
||||||
make_file('man12/man1/file12.1');
|
make_file('man12/man1/file12.1');
|
||||||
|
|
||||||
$stow = new_compat_Stow();
|
$stow = new_compat_Stow();
|
||||||
|
capture_stderr();
|
||||||
$stow->plan_unstow('pkg12');
|
$stow->plan_unstow('pkg12');
|
||||||
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg12 for third time');
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg12 for third time');
|
||||||
%conflicts = $stow->get_conflicts;
|
%conflicts = $stow->get_conflicts;
|
||||||
|
@ -290,6 +322,7 @@ ok(
|
||||||
=~ m!existing target is neither a link nor a directory: man12/man1/file12\.1!
|
=~ m!existing target is neither a link nor a directory: man12/man1/file12\.1!
|
||||||
=> 'unstow pkg12 for third time'
|
=> 'unstow pkg12 for third time'
|
||||||
);
|
);
|
||||||
|
check_protected_dirs_skipped();
|
||||||
|
|
||||||
#
|
#
|
||||||
# unstow a simple tree minimally when cwd isn't target
|
# unstow a simple tree minimally when cwd isn't target
|
||||||
|
|
Loading…
Reference in a new issue