| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# mt-aws-glacier - Amazon Glacier sync client |
|
2
|
|
|
|
|
|
|
# Copyright (C) 2012-2014 Victor Efimov |
|
3
|
|
|
|
|
|
|
# http://mt-aws.com (also http://vs-dev.com) vs@vs-dev.com |
|
4
|
|
|
|
|
|
|
# License: GPLv3 |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# This file is part of "mt-aws-glacier" |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# mt-aws-glacier is free software: you can redistribute it and/or modify |
|
9
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
|
10
|
|
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
|
11
|
|
|
|
|
|
|
# (at your option) any later version. |
|
12
|
|
|
|
|
|
|
# |
|
13
|
|
|
|
|
|
|
# mt-aws-glacier is distributed in the hope that it will be useful, |
|
14
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
|
|
|
|
# GNU General Public License for more details. |
|
17
|
|
|
|
|
|
|
# |
|
18
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
|
19
|
|
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
package App::MtAws::Command::DownloadInventory; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '1.114_2'; |
|
24
|
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
|
536
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
48
|
|
|
26
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
40
|
|
|
27
|
2
|
|
|
2
|
|
6
|
use utf8; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
8
|
|
|
28
|
2
|
|
|
2
|
|
28
|
use Carp; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
96
|
|
|
29
|
2
|
|
|
2
|
|
6
|
use App::MtAws::Utils; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
290
|
|
|
30
|
2
|
|
|
2
|
|
391
|
use App::MtAws::ForkEngine qw/with_forks fork_engine/; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
98
|
|
|
31
|
2
|
|
|
2
|
|
8
|
use App::MtAws::TreeHash; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
28
|
|
|
32
|
2
|
|
|
2
|
|
6
|
use App::MtAws::Exceptions; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
98
|
|
|
33
|
2
|
|
|
2
|
|
6
|
use App::MtAws::Journal; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
34
|
|
|
34
|
2
|
|
|
2
|
|
6
|
use App::MtAws::MetaData; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
97
|
|
|
35
|
2
|
|
|
2
|
|
8
|
use App::MtAws::DateTime; |
|
|
2
|
|
|
|
|
1
|
|
|
|
2
|
|
|
|
|
68
|
|
|
36
|
2
|
|
|
2
|
|
949
|
use App::MtAws::Glacier::Inventory::JSON; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
38
|
|
|
37
|
2
|
|
|
2
|
|
774
|
use App::MtAws::Glacier::Inventory::CSV; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
43
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
2
|
|
|
2
|
|
784
|
use App::MtAws::QueueJob::FetchAndDownloadInventory; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
562
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub run |
|
42
|
|
|
|
|
|
|
{ |
|
43
|
0
|
|
|
0
|
0
|
0
|
my ($options, $j) = @_; |
|
44
|
|
|
|
|
|
|
with_forks 1, $options, sub { |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
0
|
|
0
|
my $ft = App::MtAws::QueueJob::FetchAndDownloadInventory->new(); |
|
47
|
0
|
|
|
|
|
0
|
my ($R) = fork_engine->{parent_worker}->process_task($ft, undef); |
|
48
|
0
|
|
|
|
|
0
|
my $attachmentref = $R->{inventory_raw_ref}; |
|
49
|
0
|
|
|
|
|
0
|
my $inventory_type = $R->{inventory_type}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# here we can have response from both JobList or Inventory output.. |
|
52
|
|
|
|
|
|
|
# JobList looks like 'response' => '{"JobList":[],"Marker":null}' |
|
53
|
|
|
|
|
|
|
# Inventory retriebal has key 'ArchiveList' |
|
54
|
|
|
|
|
|
|
# TODO: implement it more clear way on level of Job/Tasks object |
|
55
|
0
|
0
|
|
|
|
0
|
croak if -s binaryfilename $options->{'new-journal'}; # TODO: fix race condition between this and opening file |
|
56
|
0
|
0
|
0
|
|
|
0
|
if ($R && $attachmentref) { # $attachmentref can be SCALAR REF or can be undef |
|
57
|
0
|
|
|
|
|
0
|
$j->open_for_write(); |
|
58
|
0
|
|
|
|
|
0
|
parse_and_write_journal($j, $inventory_type, $attachmentref); |
|
59
|
0
|
|
|
|
|
0
|
$j->close_for_write(); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
0
|
|
|
|
|
0
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub parse_and_write_journal |
|
65
|
|
|
|
|
|
|
{ |
|
66
|
6
|
|
|
6
|
0
|
93
|
my ($j, $inventory_type, $attachmentref) = @_; |
|
67
|
6
|
|
|
|
|
7
|
my $data = do { |
|
68
|
6
|
100
|
|
|
|
20
|
if ($inventory_type eq INVENTORY_TYPE_JSON) { |
|
|
|
50
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
25
|
App::MtAws::Glacier::Inventory::JSON->new($$attachmentref) |
|
70
|
|
|
|
|
|
|
} elsif ($inventory_type eq INVENTORY_TYPE_CSV) { |
|
71
|
3
|
|
|
|
|
17
|
App::MtAws::Glacier::Inventory::CSV->new($$attachmentref) |
|
72
|
|
|
|
|
|
|
} else { |
|
73
|
0
|
|
|
|
|
0
|
confess "unknown inventory type $inventory_type"; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
}->get_archives(); |
|
76
|
|
|
|
|
|
|
|
|
77
|
6
|
|
|
|
|
25
|
for my $item (@$data) { |
|
78
|
6
|
|
|
|
|
24
|
my ($relfilename, $mtime) = App::MtAws::MetaData::meta_decode($item->{ArchiveDescription}); |
|
79
|
6
|
100
|
|
|
|
13
|
$relfilename = $item->{ArchiveId} unless defined $relfilename; |
|
80
|
|
|
|
|
|
|
|
|
81
|
6
|
|
|
|
|
18
|
my $creation_time = iso8601_to_epoch($item->{CreationDate}); # TODO: move code out |
|
82
|
|
|
|
|
|
|
#time archive_id size mtime treehash relfilename |
|
83
|
|
|
|
|
|
|
$j->add_entry({ |
|
84
|
|
|
|
|
|
|
type => 'CREATED', |
|
85
|
|
|
|
|
|
|
relfilename => $relfilename, |
|
86
|
|
|
|
|
|
|
time => $creation_time, |
|
87
|
|
|
|
|
|
|
archive_id => $item->{ArchiveId}, |
|
88
|
|
|
|
|
|
|
size => $item->{Size}, |
|
89
|
|
|
|
|
|
|
mtime => $mtime, |
|
90
|
|
|
|
|
|
|
treehash => $item->{SHA256TreeHash}, |
|
91
|
6
|
|
|
|
|
153
|
}); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |