Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep track of adjusted and original dotfile paths #63

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 43 additions & 34 deletions lib/Stow.pm.in
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,16 @@ sub within_target_do {
#============================================================================
sub stow_contents {
my $self = shift;
my ($stow_path, $package, $target, $source) = @_;
my ($stow_path, $package, $package_target, $source) = @_;

my $path = join_paths($stow_path, $package, $target);
my $target = $package_target;

if ($self->{dotfiles}) {
debug(4, " Adjusting: $package_target => $target");
$target = adjust_dotfile($package_target);
}

my $path = join_paths($stow_path, $package, $package_target);

return if $self->should_skip_target_which_is_stow_dir($target);

Expand All @@ -393,15 +400,9 @@ sub stow_contents {
for my $node (@listing) {
next NODE if $node eq '.';
next NODE if $node eq '..';
my $node_target = join_paths($target, $node);
my $node_target = join_paths($package_target, $node);
next NODE if $self->ignore($stow_path, $package, $node_target);

if ($self->{dotfiles}) {
my $adj_node_target = adjust_dotfile($node_target);
debug(4, " Adjusting: $node_target => $adj_node_target");
$node_target = $adj_node_target;
}

$self->stow_node(
$stow_path,
$package,
Expand Down Expand Up @@ -429,11 +430,18 @@ sub stow_contents {
#============================================================================
sub stow_node {
my $self = shift;
my ($stow_path, $package, $target, $source) = @_;
my ($stow_path, $package, $package_target, $source) = @_;

my $path = join_paths($stow_path, $package, $target);
my $target = $package_target;

if ($self->{dotfiles}) {
debug(4, " Adjusting: $package_target => $target");
$target = adjust_dotfile($package_target);
}

debug(3, "Stowing $stow_path / $package / $target");
my $path = join_paths($stow_path, $package, $package_target);

debug(3, "Stowing $stow_path / $package / $package_target");
debug(4, " => $source");

# Don't try to stow absolute symlinks (they can't be unstowed)
Expand Down Expand Up @@ -497,13 +505,13 @@ sub stow_node {
$self->stow_contents(
$existing_stow_path,
$existing_package,
$target,
$package_target,
join_paths('..', $existing_source),
);
$self->stow_contents(
$self->{stow_path},
$package,
$target,
$package_target,
join_paths('..', $source),
);
}
Expand All @@ -529,7 +537,7 @@ sub stow_node {
$self->stow_contents(
$self->{stow_path},
$package,
$target,
$package_target,
join_paths('..', $source),
);
}
Expand All @@ -552,7 +560,7 @@ sub stow_node {
$self->stow_contents(
$self->{stow_path},
$package,
$target,
$package_target,
join_paths('..', $source),
);
}
Expand Down Expand Up @@ -740,9 +748,15 @@ sub unstow_node_orig {
#============================================================================
sub unstow_contents {
my $self = shift;
my ($stow_path, $package, $target) = @_;
my ($stow_path, $package, $package_target) = @_;

my $path = join_paths($stow_path, $package, $target);
my $target = $package_target;

if ($self->{dotfiles}) {
$target = adjust_dotfile($package_target);
}

my $path = join_paths($stow_path, $package, $package_target);

return if $self->should_skip_target_which_is_stow_dir($target);

Expand All @@ -769,15 +783,9 @@ sub unstow_contents {
for my $node (@listing) {
next NODE if $node eq '.';
next NODE if $node eq '..';
my $node_target = join_paths($target, $node);
my $node_target = join_paths($package_target, $node);
next NODE if $self->ignore($stow_path, $package, $node_target);

if ($self->{dotfiles}) {
my $adj_node_target = adjust_dotfile($node_target);
debug(4, " Adjusting: $node_target => $adj_node_target");
$node_target = $adj_node_target;
}

$self->unstow_node($stow_path, $package, $node_target);
}
if (-d $target) {
Expand All @@ -798,9 +806,15 @@ sub unstow_contents {
#============================================================================
sub unstow_node {
my $self = shift;
my ($stow_path, $package, $target) = @_;
my ($stow_path, $package, $package_target) = @_;

my $path = join_paths($stow_path, $package, $target);
my $target = $package_target;

if ($self->{dotfiles}) {
$target = adjust_dotfile($package_target);
}

my $path = join_paths($stow_path, $package, $package_target);

debug(3, "Unstowing $path");
debug(4, " target is $target");
Expand Down Expand Up @@ -836,11 +850,6 @@ sub unstow_node {
if (-e $existing_path) {
# Does link points to the right place?

# Adjust for dotfile if necessary.
if ($self->{dotfiles}) {
$existing_path = adjust_dotfile($existing_path);
}

if ($existing_path eq $path) {
$self->do_unlink($target);
}
Expand Down Expand Up @@ -872,11 +881,11 @@ sub unstow_node {
elsif (-e $target) {
debug(4, " Evaluate existing node: $target");
if (-d $target) {
$self->unstow_contents($stow_path, $package, $target);
$self->unstow_contents($stow_path, $package, $package_target);

# This action may have made the parent directory foldable
if (my $parent = $self->foldable($target)) {
$self->fold_tree($target, $parent);
$self->fold_tree($package_target, $parent);
}
}
else {
Expand Down
52 changes: 51 additions & 1 deletion t/dotfiles.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use warnings;

use testutil;

use Test::More tests => 6;
use Test::More tests => 9;
use English qw(-no_match_vars);

use testutil;
Expand Down Expand Up @@ -129,3 +129,53 @@ ok(
-f '../stow/dotfiles/dot-bar' && ! -e '.bar'
=> 'unstow a simple dotfile'
);

#
# stow into existing directory
#

$stow = new_Stow(dir => '../stow', dotfiles => 1);

make_path('.config');
make_path('../stow/emacs/dot-config/emacs');
make_file('../stow/emacs/dot-config/emacs/init.el');

$stow->plan_stow('emacs');
$stow->process_tasks();
is(
readlink('.config/emacs'),
'../../stow/emacs/dot-config/emacs',
=> 'processed dotfile folder into existing folder'
);

#
# unstow from existing directory
#

$stow = new_Stow(dir => '../stow', dotfiles => 1);

$stow->plan_unstow('emacs');
$stow->process_tasks();
ok(
$stow->get_conflict_count == 0 &&
-d '.config' && ! -e '.config/stow' &&
-f '../stow/emacs/dot-config/emacs/init.el'
=> 'unstow from a directory'
);

#
# package containing a dot dir, no folding
#

$stow = new_Stow(dir => '../stow', dotfiles => 1, 'no-folding' => 1);

make_path('../stow/emacs/dot-config/emacs');
make_file('../stow/emacs/dot-config/emacs/init.el');

$stow->plan_stow('emacs');
$stow->process_tasks();
is(
readlink('.config/emacs/init.el'),
'../../../stow/emacs/dot-config/emacs/init.el',
=> 'processed dotfile folder without folding'
);