Correctly handle empty STOW_DIR (#5, #6)

In shell, a variable is often considered unset even if it is
set to the empty string.  In other words,

  STOW_DIR= stow [args]

is an idiomatic alternative to writing:

  unset STOW_DIR
  stow [args]

and it also has the advantage of temporarily "unsetting" STOW_DIR
for a single command.

Therefore we should treat STOW_DIR being set to the empty string
as equivalent to it not being set at all.

Thanks to Cuong Manh Le for highlighting this issue!

Fixes #6  - https://github.com/aspiers/stow/issues/6
Closes #5 - https://github.com/aspiers/stow/pull/5
This commit is contained in:
Adam Spiers 2015-11-11 11:22:05 +00:00
parent b5dbc3b7b4
commit d0f3e5458f
2 changed files with 2 additions and 1 deletions

1
THANKS
View file

@ -23,3 +23,4 @@ Christopher Hoobin <christopher.hoobin.edu.au>
Adam Spiers <stow@adamspiers.org> Adam Spiers <stow@adamspiers.org>
Stefano Lattarini Stefano Lattarini
Adam Sampson Adam Sampson
Cuong Manh Le

View file

@ -542,7 +542,7 @@ sub sanitize_path_options {
$options->{dir} =~ s/ +\z//; $options->{dir} =~ s/ +\z//;
} }
else { else {
$options->{dir} = exists $ENV{STOW_DIR} ? $ENV{STOW_DIR} : getcwd(); $options->{dir} = $ENV{STOW_DIR} ? $ENV{STOW_DIR} : getcwd();
} }
if (exists $options->{target}) { if (exists $options->{target}) {