From d1f2e50c0aca2471861bcd08bde3592fd5c51f36 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sat, 15 Feb 2020 23:46:12 +0000 Subject: [PATCH 1/3] Add option to use absolute paths and add --no-folding to usage --- bin/stow.in | 12 +++++++++++- lib/Stow.pm.in | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/bin/stow.in b/bin/stow.in index 4faa451..6a29974 100755 --- a/bin/stow.in +++ b/bin/stow.in @@ -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. @@ -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' => @@ -814,6 +820,10 @@ 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 + + --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 diff --git a/lib/Stow.pm.in b/lib/Stow.pm.in index 77f67b3..b11e91a 100755 --- a/lib/Stow.pm.in +++ b/lib/Stow.pm.in @@ -78,6 +78,7 @@ our %DEFAULT_OPTIONS = ( dotfiles => 0, adopt => 0, 'no-folding' => 0, + absolute => 0, ignore => [], override => [], defer => [], @@ -119,6 +120,8 @@ See the documentation for the F CLI front-end for information on these. =item * no-folding +=item * absolute + =item * ignore =item * override @@ -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 { @@ -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( @@ -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? From f2c89596ae1e2901517e1dc3a742e2b1c6df0acf Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 16 Feb 2020 00:07:56 +0000 Subject: [PATCH 2/3] Allow unstowing absolute path links if given -a option --- lib/Stow.pm.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Stow.pm.in b/lib/Stow.pm.in index b11e91a..3a36f45 100755 --- a/lib/Stow.pm.in +++ b/lib/Stow.pm.in @@ -445,7 +445,7 @@ sub stow_node { debug(4, " => $source"); # Don't try to stow absolute symlinks (they can't be unstowed) - if (not $self->{absolute} && -l $source) { + if ((not $self->{absolute}) && -l $source) { my $second_source = $self->read_a_link($source); if ($second_source =~ m{\A/}) { $self->conflict( @@ -827,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 # } From fe85454971b6ce7e39ffeefa88d9cb30297bab09 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 16 Feb 2020 21:33:37 +0000 Subject: [PATCH 3/3] Add --dotfiles to usage output --- bin/stow.in | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/stow.in b/bin/stow.in index 6a29974..c3c2a7b 100755 --- a/bin/stow.in +++ b/bin/stow.in @@ -821,6 +821,7 @@ OPTIONS: -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.