Merge commit 'pullreqs/70' into dev
This commit is contained in:
commit
2f762e3908
2 changed files with 99 additions and 11 deletions
|
@ -285,12 +285,14 @@ sub plan_unstow {
|
||||||
$self->unstow_contents_orig(
|
$self->unstow_contents_orig(
|
||||||
$package,
|
$package,
|
||||||
'.',
|
'.',
|
||||||
|
$pkg_path,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$self->unstow_contents(
|
$self->unstow_contents(
|
||||||
$package,
|
$package,
|
||||||
'.',
|
'.',
|
||||||
|
$pkg_path,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
debug(2, 0, "Planning unstow of package $package... done");
|
debug(2, 0, "Planning unstow of package $package... done");
|
||||||
|
@ -327,6 +329,7 @@ sub plan_stow {
|
||||||
$package,
|
$package,
|
||||||
'.',
|
'.',
|
||||||
$pkg_path, # source from target
|
$pkg_path, # source from target
|
||||||
|
0,
|
||||||
);
|
);
|
||||||
debug(2, 0, "Planning stow of package $package... done");
|
debug(2, 0, "Planning stow of package $package... done");
|
||||||
$self->{action_count}++;
|
$self->{action_count}++;
|
||||||
|
@ -404,7 +407,7 @@ folding/unfolding trees as necessary.
|
||||||
|
|
||||||
sub stow_contents {
|
sub stow_contents {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($stow_path, $package, $target, $source) = @_;
|
my ($stow_path, $package, $target, $source, $level) = @_;
|
||||||
|
|
||||||
# Calculate the path to the package directory or sub-directory
|
# Calculate the path to the package directory or sub-directory
|
||||||
# whose contents need to be stowed, relative to the current
|
# whose contents need to be stowed, relative to the current
|
||||||
|
@ -415,7 +418,10 @@ sub stow_contents {
|
||||||
# but instead it's relative to the target directory or
|
# but instead it's relative to the target directory or
|
||||||
# sub-directory where the symlink will be installed when the plans
|
# sub-directory where the symlink will be installed when the plans
|
||||||
# are executed.
|
# are executed.
|
||||||
my $path = join_paths($stow_path, $package, $target);
|
|
||||||
|
# Remove leading $level times .. from $source
|
||||||
|
my $n = 0;
|
||||||
|
my $path = join '/', map { (++$n <= $level) ? ( ) : $_ } (split m{/+}, $source);
|
||||||
|
|
||||||
return if $self->should_skip_target($target);
|
return if $self->should_skip_target($target);
|
||||||
|
|
||||||
|
@ -453,6 +459,7 @@ sub stow_contents {
|
||||||
$package,
|
$package,
|
||||||
$node_target, # target, potentially adjusted for dot- prefix
|
$node_target, # target, potentially adjusted for dot- prefix
|
||||||
join_paths($source, $node), # source
|
join_paths($source, $node), # source
|
||||||
|
$level
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -494,7 +501,7 @@ folding/unfolding trees as necessary.
|
||||||
|
|
||||||
sub stow_node {
|
sub stow_node {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($stow_path, $package, $target, $source) = @_;
|
my ($stow_path, $package, $target, $source, $level) = @_;
|
||||||
|
|
||||||
my $path = join_paths($stow_path, $package, $target);
|
my $path = join_paths($stow_path, $package, $target);
|
||||||
|
|
||||||
|
@ -564,12 +571,14 @@ sub stow_node {
|
||||||
$existing_package,
|
$existing_package,
|
||||||
$target,
|
$target,
|
||||||
join_paths('..', $existing_source),
|
join_paths('..', $existing_source),
|
||||||
|
$level + 1,
|
||||||
);
|
);
|
||||||
$self->stow_contents(
|
$self->stow_contents(
|
||||||
$self->{stow_path},
|
$self->{stow_path},
|
||||||
$package,
|
$package,
|
||||||
$target,
|
$target,
|
||||||
join_paths('..', $source),
|
join_paths('..', $source),
|
||||||
|
$level + 1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -596,6 +605,7 @@ sub stow_node {
|
||||||
$package,
|
$package,
|
||||||
$target,
|
$target,
|
||||||
join_paths('..', $source),
|
join_paths('..', $source),
|
||||||
|
$level + 1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -619,6 +629,7 @@ sub stow_node {
|
||||||
$package,
|
$package,
|
||||||
$target,
|
$target,
|
||||||
join_paths('..', $source),
|
join_paths('..', $source),
|
||||||
|
$level + 1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -846,9 +857,7 @@ Here we traverse the source tree, rather than the target tree.
|
||||||
|
|
||||||
sub unstow_contents {
|
sub unstow_contents {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($package, $target) = @_;
|
my ($package, $target, $path) = @_;
|
||||||
|
|
||||||
my $path = join_paths($self->{stow_path}, $package, $target);
|
|
||||||
|
|
||||||
return if $self->should_skip_target($target);
|
return if $self->should_skip_target($target);
|
||||||
|
|
||||||
|
@ -884,7 +893,7 @@ sub unstow_contents {
|
||||||
$node_target = $adj_node_target;
|
$node_target = $adj_node_target;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->unstow_node($package, $node_target);
|
$self->unstow_node($package, $node_target, join_paths($path, $node));
|
||||||
}
|
}
|
||||||
if (-d $target) {
|
if (-d $target) {
|
||||||
$self->cleanup_invalid_links($target);
|
$self->cleanup_invalid_links($target);
|
||||||
|
@ -913,7 +922,7 @@ C<unstow_node()> and C<unstow_contents()> are mutually recursive.
|
||||||
|
|
||||||
sub unstow_node {
|
sub unstow_node {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($package, $target) = @_;
|
my ($package, $target, $source) = @_;
|
||||||
|
|
||||||
my $path = join_paths($self->{stow_path}, $package, $target);
|
my $path = join_paths($self->{stow_path}, $package, $target);
|
||||||
|
|
||||||
|
@ -987,7 +996,7 @@ sub unstow_node {
|
||||||
elsif (-e $target) {
|
elsif (-e $target) {
|
||||||
debug(4, 2, "Evaluate existing node: $target");
|
debug(4, 2, "Evaluate existing node: $target");
|
||||||
if (-d $target) {
|
if (-d $target) {
|
||||||
$self->unstow_contents($package, $target);
|
$self->unstow_contents($package, $target, $source);
|
||||||
|
|
||||||
# This action may have made the parent directory foldable
|
# This action may have made the parent directory foldable
|
||||||
if (my $parent = $self->foldable($target)) {
|
if (my $parent = $self->foldable($target)) {
|
||||||
|
|
83
t/dotfiles.t
83
t/dotfiles.t
|
@ -24,7 +24,7 @@ use warnings;
|
||||||
|
|
||||||
use testutil;
|
use testutil;
|
||||||
|
|
||||||
use Test::More tests => 6;
|
use Test::More tests => 10;
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
|
|
||||||
use testutil;
|
use testutil;
|
||||||
|
@ -87,7 +87,64 @@ is(
|
||||||
);
|
);
|
||||||
|
|
||||||
#
|
#
|
||||||
# corner case: paths with a part in them that's just "$DOT_PREFIX" or
|
# process folder marked with 'dot' prefix
|
||||||
|
# when directory exists is target
|
||||||
|
#
|
||||||
|
|
||||||
|
$stow = new_Stow(dir => '../stow', dotfiles => 1);
|
||||||
|
|
||||||
|
make_path('../stow/dotfiles/dot-emacs.d');
|
||||||
|
make_file('../stow/dotfiles/dot-emacs.d/init.el');
|
||||||
|
make_path('.emacs.d');
|
||||||
|
|
||||||
|
$stow->plan_stow('dotfiles');
|
||||||
|
$stow->process_tasks();
|
||||||
|
is(
|
||||||
|
readlink('.emacs.d/init.el'),
|
||||||
|
'../../stow/dotfiles/dot-emacs.d/init.el',
|
||||||
|
=> 'processed dotfile folder when folder exists (1 level)'
|
||||||
|
);
|
||||||
|
|
||||||
|
#
|
||||||
|
# process folder marked with 'dot' prefix
|
||||||
|
# when directory exists is target (2 levels)
|
||||||
|
#
|
||||||
|
|
||||||
|
$stow = new_Stow(dir => '../stow', dotfiles => 1);
|
||||||
|
|
||||||
|
make_path('../stow/dotfiles/dot-emacs.d/dot-emacs.d');
|
||||||
|
make_file('../stow/dotfiles/dot-emacs.d/dot-emacs.d/init.el');
|
||||||
|
make_path('.emacs.d');
|
||||||
|
|
||||||
|
$stow->plan_stow('dotfiles');
|
||||||
|
$stow->process_tasks();
|
||||||
|
is(
|
||||||
|
readlink('.emacs.d/.emacs.d'),
|
||||||
|
'../../stow/dotfiles/dot-emacs.d/dot-emacs.d',
|
||||||
|
=> 'processed dotfile folder exists (2 levels)'
|
||||||
|
);
|
||||||
|
|
||||||
|
#
|
||||||
|
# process folder marked with 'dot' prefix
|
||||||
|
# when directory exists is target
|
||||||
|
#
|
||||||
|
|
||||||
|
$stow = new_Stow(dir => '../stow', dotfiles => 1);
|
||||||
|
|
||||||
|
make_path('../stow/dotfiles/dot-one/dot-two');
|
||||||
|
make_file('../stow/dotfiles/dot-one/dot-two/three');
|
||||||
|
make_path('.one/.two');
|
||||||
|
|
||||||
|
$stow->plan_stow('dotfiles');
|
||||||
|
$stow->process_tasks();
|
||||||
|
is(
|
||||||
|
readlink('./.one/.two/three'),
|
||||||
|
'../../../stow/dotfiles/dot-one/dot-two/three',
|
||||||
|
=> 'processed dotfile 2 folder exists (2 levels)'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
# "$DOT_PREFIX." should not have that part expanded.
|
# "$DOT_PREFIX." should not have that part expanded.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
@ -129,3 +186,25 @@ ok(
|
||||||
-f '../stow/dotfiles/dot-bar' && ! -e '.bar'
|
-f '../stow/dotfiles/dot-bar' && ! -e '.bar'
|
||||||
=> 'unstow a simple dotfile'
|
=> 'unstow a simple dotfile'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#
|
||||||
|
# unstow process folder marked with 'dot' prefix
|
||||||
|
# when directory exists is target
|
||||||
|
#
|
||||||
|
|
||||||
|
$stow = new_Stow(dir => '../stow', dotfiles => 1);
|
||||||
|
|
||||||
|
make_path('../stow/dotfiles/dot-emacs.d');
|
||||||
|
make_file('../stow/dotfiles/dot-emacs.d/init.el');
|
||||||
|
make_path('.emacs.d');
|
||||||
|
make_link('.emacs.d/init.el', '../../stow/dotfiles/dot-emacs.d/init.el');
|
||||||
|
|
||||||
|
$stow->plan_unstow('dotfiles');
|
||||||
|
$stow->process_tasks();
|
||||||
|
ok(
|
||||||
|
$stow->get_conflict_count == 0 &&
|
||||||
|
-f '../stow/dotfiles/dot-emacs.d/init.el' &&
|
||||||
|
! -e '.emacs.d/init.el' &&
|
||||||
|
-d '.emacs.d/'
|
||||||
|
=> 'unstow dotfile folder when folder already exists'
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in a new issue