App-Glacier
view release on metacpan or search on metacpan
lib/App/Glacier/Command/Get.pm view on Meta::CPAN
I<FILE>
[I<LOCALNAME>]
=head1 DESCRIPTION
Downloads I<FILE> from the I<VAULT>. The local file name for the file is
supplied by the I<LOCALNAME>. If this argument is absent, the local name
is formed from I<FILE> with the eventual version number part removed.
See B<glacier>(1), section B<On file versioning>, for the
information about file versioning scheme.
=head1 OPTION
=over 4
=item B<-f>, B<--force>
Silently overwrites existing local file.
=item B<-i>, B<--interactive>
If the local file already exists, asks for permission before overwriting
it.
=item B<-j>, B<--jobs=>I<N>
Sets the number of concurrent download jobs for multiple-part downloads.
The default is configured by the B<transfer.download.jobs> configuration
statement. If absent, the B<transfer.jobs> statement is used. The
default value is 16.
=item B<-k>, B<--keep>, B<--no-clobber>
Never overwrite existing files.
=item B<-q>, B<--quiet>
Don't display progress meter during multi-part downloads.
=item B<-t>, B<--test>
Test mode. Don't download the file, display only the status of the
correspondig archive retrieval job.
=back
=head1 SEE ALSO
B<glacier>(1).
=cut
use constant {
IFEXISTS_OVERWRITE => 0,
IFEXISTS_KEEP => 1,
IFEXISTS_ASK => 2,
};
sub new {
my ($class, $argref, %opts) = @_;
my $self = $class->SUPER::new(
$argref,
optmap => {
'interactive|i' => sub {
$_[0]->{_options}{ifexists} = IFEXISTS_ASK
},
'force|f' => sub {
$_[0]->{_options}{ifexists} = IFEXISTS_OVERWRITE
},
'no-clobber|keep|k' => sub {
$_[0]->{_options}{ifexists} = IFEXISTS_KEEP
},
'quiet|q' => 'quiet',
'jobs|j=i' => 'jobs',
'test|t' => 'test'
},
%opts);
$self->{_options}{ifexists} //= IFEXISTS_OVERWRITE;
return $self;
}
sub run {
my $self = shift;
$self->abend(EX_USAGE, "two or three arguments expected")
unless $self->command_line == 2 || $self->command_line == 3;
my ($vaultname, $filespec, $localname) = $self->command_line;
$filespec =~ /^(?<file>.+?)(?:(?<!\\);(?<ver>\d+))?$/
or die "unexpected failure";
my ($filename, $ver) = ($+{file}, $+{ver});
# Reset $ver and $filespec for error reporting
$ver = 1 unless defined $ver;
$filespec = "$filespec;$ver";
$localname = $filename unless defined($localname);
if (-e $localname) {
if ($self->{_options}{ifexists} == IFEXISTS_ASK) {
$self->{_options}{ifexists} =
$self->getyn("\"$localname\" already exists, overwrite")
? IFEXISTS_OVERWRITE : IFEXISTS_KEEP;
}
if ($self->{_options}{ifexists} == IFEXISTS_KEEP) {
exit(EX_NOPERM);
}
}
my $job = new App::Glacier::Job::FileRetrieval($self, $vaultname,
$filename, $ver);
if ($self->{_options}{test}) {
print "downloading file $filename initialized on ",
$job->get('CreationDate')->canned_format('full-iso'),"\n";
print "job id: ", $job->id, "\n";
my ($status, $message) = $job->status;
print "current status: $status\n";
if ($message) {
print "status message: $message\n";
}
( run in 0.644 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )