Separate treatment of .stow and .nonstow marked dirs

Placing a .stow file in a directory tells Stow that this directory
should be considered a Stow directory.  This is already
well-documented.

There was an undocumented and slightly broken feature where placing a
.nonstow file in a directory was treated in exactly the same way.  The
intention was for .nonstow to cause Stow to skip stowing into and
unstowing from that directory and any of its descendants.  However, it
also caused Stow to consider symlinks into any of those directories as
owned by Stow, even though that was clearly not the intention.  So
separate treatment of .stow and .nonstow markers, so that while both
provide protection against Stow stowing and unstowing, only .stow
affects the symlink ownership logic in find_stowed_path() and
marked_stow_dir().

Probably no one uses the undocumented .nonstow feature, so it may make
sense to remove this in future.
This commit is contained in:
Adam Spiers 2024-03-30 14:03:56 +00:00
parent 287d8016f6
commit a2beb7b371
3 changed files with 22 additions and 16 deletions

View file

@ -395,7 +395,7 @@ sub stow_contents {
# are executed.
my $path = join_paths($stow_path, $package, $target);
return if $self->should_skip_target_which_is_stow_dir($target);
return if $self->should_skip_target($target);
my $cwd = getcwd();
my $msg = "Stowing contents of $path (cwd=$cwd)";
@ -587,15 +587,16 @@ sub stow_node {
}
#===== METHOD ===============================================================
# Name : should_skip_target_which_is_stow_dir()
# Name : should_skip_target()
# Purpose : determine whether target is a stow directory which should
# : not be stowed to or unstowed from
# Parameters: $target => relative path to symlink target from the current directory
# Returns : true iff target is a stow directory
# Throws : n/a
# Comments : none
# Comments : cwd must be the top-level target directory, otherwise
# : marked_stow_dir() won't work.
#============================================================================
sub should_skip_target_which_is_stow_dir {
sub should_skip_target {
my $self = shift;
my ($target) = @_;
@ -606,23 +607,28 @@ sub should_skip_target_which_is_stow_dir {
}
if ($self->marked_stow_dir($target)) {
warn "WARNING: skipping marked Stow directory $target\n";
return 1;
}
if (-e join_paths($target, ".nonstow")) {
warn "WARNING: skipping protected directory $target\n";
return 1;
}
debug(4, 1, "$target not protected");
debug(4, 1, "$target not protected; shouldn't skip");
return 0;
}
# cwd must be the top-level target directory, otherwise
# marked_stow_dir() won't work.
sub marked_stow_dir {
my $self = shift;
my ($target) = @_;
for my $f (".stow", ".nonstow") {
if (-e join_paths($target, $f)) {
debug(4, 2, "$target contained $f");
my ($path) = @_;
if (-e join_paths($path, ".stow")) {
debug(5, 5, "> $path contained .stow");
return 1;
}
}
return 0;
}
@ -642,7 +648,7 @@ sub unstow_contents_orig {
my $path = join_paths($self->{stow_path}, $package, $target);
return if $self->should_skip_target_which_is_stow_dir($target);
return if $self->should_skip_target($target);
my $cwd = getcwd();
my $msg = "Unstowing from $target (compat mode, cwd=$cwd, stow dir=$self->{stow_path})";
@ -762,7 +768,7 @@ sub unstow_contents {
my $path = join_paths($self->{stow_path}, $package, $target);
return if $self->should_skip_target_which_is_stow_dir($target);
return if $self->should_skip_target($target);
my $cwd = getcwd();
my $msg = "Unstowing from $target (cwd=$cwd, stow dir=$self->{stow_path})";

View file

@ -193,7 +193,7 @@ ok(
=> q(don't unlink any nodes under another stow directory)
);
like($stderr,
qr/WARNING: skipping protected directory stow2/
qr/WARNING: skipping marked Stow directory stow2/
=> "unstowing from ourself should skip stow");
uncapture_stderr();

View file

@ -216,8 +216,8 @@ uncapture_stderr();
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");
qr/WARNING: skipping marked Stow directory $dir/
=> "warn when skipping marked directory $dir");
}
uncapture_stderr();
}