diff options
author | Joris Vankerschaver <jvankerschaver@enthought.com> | 2016-07-31 21:55:55 +0100 |
---|---|---|
committer | Joris Vankerschaver <jvankerschaver@enthought.com> | 2016-10-04 17:51:01 +0100 |
commit | 182acbbb64425bf95008cb6d42d266f6185032c9 (patch) | |
tree | 79ae2e75985a455ce473fbde3361ff4dd6a45eee /lib | |
parent | c171ca8d839e0cd3d67d754b442c38865b6a8c4f (diff) | |
download | stow-182acbbb64425bf95008cb6d42d266f6185032c9.tar.gz |
Special processing for dotfiles
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Stow.pm.in | 23 | ||||
-rw-r--r-- | lib/Stow/Util.pm.in | 16 |
2 files changed, 37 insertions, 2 deletions
diff --git a/lib/Stow.pm.in b/lib/Stow.pm.in index 851bb86..2f66446 100755 --- a/lib/Stow.pm.in +++ b/lib/Stow.pm.in @@ -41,7 +41,7 @@ use File::Spec; use POSIX qw(getcwd); use Stow::Util qw(set_debug_level debug error set_test_mode - join_paths restore_cwd canon_path parent); + join_paths restore_cwd canon_path parent adjust_dotfile); our $ProgramName = 'stow'; our $VERSION = '@VERSION@'; @@ -60,6 +60,7 @@ our %DEFAULT_OPTIONS = ( paranoid => 0, compat => 0, test_mode => 0, + dotfiles => 0, adopt => 0, 'no-folding' => 0, ignore => [], @@ -377,6 +378,13 @@ sub stow_contents { next NODE if $node eq '..'; my $node_target = join_paths($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, @@ -744,6 +752,13 @@ sub unstow_contents { next NODE if $node eq '..'; my $node_target = join_paths($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) { @@ -801,6 +816,12 @@ sub unstow_node { # Does the existing $target actually point to anything? 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); } diff --git a/lib/Stow/Util.pm.in b/lib/Stow/Util.pm.in index b709e7e..451a143 100644 --- a/lib/Stow/Util.pm.in +++ b/lib/Stow/Util.pm.in @@ -22,7 +22,7 @@ use POSIX qw(getcwd); use base qw(Exporter); our @EXPORT_OK = qw( error debug set_debug_level set_test_mode - join_paths parent canon_path restore_cwd + join_paths parent canon_path restore_cwd adjust_dotfile ); our $ProgramName = 'stow'; @@ -193,6 +193,20 @@ sub restore_cwd { chdir($prev) or error("Your current directory $prev seems to have vanished"); } +sub adjust_dotfile { + my ($target) = @_; + + my @result = (); + for my $part (split m{/+}, $target) { + if (($part ne "dot-") && ($part ne "dot-.")) { + $part =~ s/^dot-/./; + } + push @result, $part; + } + + return join '/', @result; +} + =head1 BUGS =head1 SEE ALSO |