Skip to content

Commit

Permalink
Merge fe85454 into 9fd3624
Browse files Browse the repository at this point in the history
  • Loading branch information
someonewithpc committed Feb 16, 2020
2 parents 9fd3624 + fe85454 commit 084e323
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
13 changes: 12 additions & 1 deletion bin/stow.in
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ changing.
Disable folding of newly stowed directories when stowing, and
refolding of newly foldable directories when unstowing.
=item --absolute
=item -a
Use absolute paths
=item --ignore=REGEX
Ignore files ending in this Perl regex.
Expand Down Expand Up @@ -574,7 +580,7 @@ sub parse_options {
\%options,
'verbose|v:+', 'help|h', 'simulate|n|no',
'version|V', 'compat|p', 'dir|d=s', 'target|t=s',
'adopt', 'no-folding', 'dotfiles',
'adopt', 'no-folding', 'dotfiles', 'absolute|a',

# clean and pre-compile any regex's at parse time
'ignore=s' =>
Expand Down Expand Up @@ -814,6 +820,11 @@ OPTIONS:
-D, --delete Unstow the package names that follow this option
-R, --restow Restow (like stow -D followed by stow -S)
-a, --absolute Use absolute paths
--dotfiles Convert filenames starting with `dot-' to `.'
--no-folding Disable folding of newly stowed directories when stowing,
and refolding of newly foldable directories when unstowing.
--ignore=REGEX Ignore files ending in this Perl regex
--defer=REGEX Don't stow files beginning with this Perl regex
if the file is already stowed to another package
Expand Down
20 changes: 16 additions & 4 deletions lib/Stow.pm.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ our %DEFAULT_OPTIONS = (
dotfiles => 0,
adopt => 0,
'no-folding' => 0,
absolute => 0,
ignore => [],
override => [],
defer => [],
Expand Down Expand Up @@ -119,6 +120,8 @@ See the documentation for the F<stow> CLI front-end for information on these.
=item * no-folding
=item * absolute
=item * ignore
=item * override
Expand Down Expand Up @@ -202,10 +205,15 @@ sub set_stow_dir {

my $stow_dir = canon_path($self->{dir});
my $target = canon_path($self->{target});
$self->{stow_path} = File::Spec->abs2rel($stow_dir, $target);
$self->{stow_path} = $self->{absolute} ? $stow_dir :
File::Spec->abs2rel($stow_dir, $target);

debug(2, "stow dir is $stow_dir");
debug(2, "stow dir path relative to target $target is $self->{stow_path}");
if (!$self->{absolute}) {
debug(2, "stow dir path relative to target $target is $self->{stow_path}");
} else {
debug(2, "stow dir path for target $target is $self->{stow_path}");
}
}

sub init_state {
Expand Down Expand Up @@ -437,7 +445,7 @@ sub stow_node {
debug(4, " => $source");

# Don't try to stow absolute symlinks (they can't be unstowed)
if (-l $source) {
if ((not $self->{absolute}) && -l $source) {
my $second_source = $self->read_a_link($source);
if ($second_source =~ m{\A/}) {
$self->conflict(
Expand All @@ -450,6 +458,10 @@ sub stow_node {
}
}

if ($self->{absolute}) {
debug(3, "Absolute symlinks cannot be unstowed, proceeding due to command-line option");
}

# Does the target already exist?
if ($self->is_a_link($target)) {
# Where is the link pointing?
Expand Down Expand Up @@ -815,7 +827,7 @@ sub unstow_node {
error("Could not read link: $target");
}

if ($existing_source =~ m{\A/}) {
if (not $self->{absolute} and $existing_source =~ m{\A/}) {
warn "Ignoring an absolute symlink: $target => $existing_source\n";
return; # XXX #
}
Expand Down

0 comments on commit 084e323

Please sign in to comment.