checkdir('/usr/tmp', sub { -w $_ });
checkdir('/usr/tmp', sub { -r $_ });
checkdir('/usr/tmp', sub { -r $_ and -w $_ });
####
# now it's:
checkdir('/usr/tmp', sub { -r $_ and -w _ });
checkdir('/usr/tmp', sub { !/\.\./ });
####
use List::MoreUtils qw/none/;
use File::Spec;
checkdir('/usr/tmp', sub {
none { $_ eq '..' } File::Spec->splitdir($_)
});
####
sub checkDir {
my ($path, $perm) = @_;
### Check if output dir exists
if (! defined $path) {
LOG ("Output path not defined; using temp instead...", 1);
$path = '/var/tmp/';
}
if (! -d $path) {
die LOG ("$path is not a valid directory...", 0);
}
if (! do { local $_ = $path; $perm->() }) {
die LOG ("Test failed on $path, not able to use it.", 0);
}
LOG ("Using $path as output directory...", 2);
}