App-DownloadsDirUtils
view release on metacpan or search on metacpan
lib/App/DownloadsDirUtils.pm view on Meta::CPAN
no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
require File::Basename;
require File::Copy::Recursive;
my %args = @_;
my $to_dir = delete($args{to_dir}) // '.';
my $res = &{"${which}_download"}(%args);
return $res unless $res->[0] == 200;
return [404, "No $which file(s) returned"] unless @{ $res->[2] };
my $envres = envresmulti();
my $i = 0;
for my $file (@{ $res->[2] }) {
$i++;
my $targetpath = $to_dir . '/' . ($args{as} // File::Basename::basename($file));
if (-e $targetpath && !$args{overwrite}) {
$envres->add_result(409, "File already exists '$targetpath', please specify -O to overwrite", {item_id=>$file});
} elsif ($args{-dry_run}) {
log_info "DRY-RUN: [%d/%d] Moving %s to %s ...", $i, scalar(@{ $res->[2] }), $file, $targetpath;
( run in 0.675 second using v1.01-cache-2.11-cpan-39bf76dae61 )