Do more validation on --dir / --target directories (#7)

Previously STOW_DIR=0 would cause the cwd to be used as the STOW_DIR.
Make that instead raise an error.  Do similar validation on the target
directory.

Closes #7 - https://github.com/aspiers/stow/pull/7
This commit is contained in:
Adam Spiers 2015-11-11 12:25:19 +00:00
parent d0f3e5458f
commit a111eeb8ae

View file

@ -542,12 +542,17 @@ sub sanitize_path_options {
$options->{dir} =~ s/ +\z//; $options->{dir} =~ s/ +\z//;
} }
else { else {
$options->{dir} = $ENV{STOW_DIR} ? $ENV{STOW_DIR} : getcwd(); $options->{dir} = length $ENV{STOW_DIR} ? $ENV{STOW_DIR} : getcwd();
} }
usage("--dir value '$options->{dir}' is not a valid directory")
unless -d $options->{dir};
if (exists $options->{target}) { if (exists $options->{target}) {
$options->{target} =~ s/\A +//; $options->{target} =~ s/\A +//;
$options->{target} =~ s/ +\z//; $options->{target} =~ s/ +\z//;
usage("--target value '$options->{target}' is not a valid directory")
unless -d $options->{target};
} }
else { else {
$options->{target} = parent($options->{dir}) || '.'; $options->{target} = parent($options->{dir}) || '.';