| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package File::HStore; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24379
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
31
|
|
|
5
|
1
|
|
|
1
|
|
8844
|
use Digest::SHA; |
|
|
1
|
|
|
|
|
6472
|
|
|
|
1
|
|
|
|
|
86
|
|
|
6
|
1
|
|
|
1
|
|
1333
|
use File::Copy; |
|
|
1
|
|
|
|
|
9546
|
|
|
|
1
|
|
|
|
|
202
|
|
|
7
|
1
|
|
|
1
|
|
10
|
use File::Path; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
69
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
|
10
|
1
|
|
|
1
|
|
2059
|
use AutoLoader qw(AUTOLOAD); |
|
|
1
|
|
|
|
|
1611
|
|
|
|
1
|
|
|
|
|
6
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
|
15
|
|
|
|
|
|
|
'all' => [ |
|
16
|
|
|
|
|
|
|
qw( |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
) |
|
19
|
|
|
|
|
|
|
] |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT = qw( ); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
|
0
|
1
|
|
my ( $this, $path, $digest, $prefix ) = @_; |
|
31
|
0
|
|
0
|
|
|
|
my $class = ref($this) || $this; |
|
32
|
0
|
|
|
|
|
|
my $self = {}; |
|
33
|
0
|
|
|
|
|
|
bless $self, $class; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
if ( defined($path) ) { |
|
36
|
0
|
|
|
|
|
|
$self->{path} = $path; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
else { |
|
39
|
0
|
|
|
|
|
|
$self->{path} = "~/.hstore"; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
if ( defined($digest) ) { |
|
43
|
0
|
|
|
|
|
|
$self->{digest} = $digest; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
else { |
|
46
|
0
|
|
|
|
|
|
$self->{digest} = "SHA1"; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ( defined($prefix) ) { |
|
50
|
0
|
|
|
|
|
|
$self->{prefix} = $prefix; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
else { |
|
53
|
0
|
|
|
|
|
|
$self->{prefix} = "freearchive"; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if ( !( -e $self->{path} ) ) { |
|
57
|
0
|
0
|
|
|
|
|
mkdir( $self->{path} ) |
|
58
|
|
|
|
|
|
|
or die "Unable to create directory : $self->{path}"; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $self; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub add { |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
0
|
1
|
|
my ( $self, $filename ) = @_; |
|
67
|
0
|
|
|
|
|
|
my $ldigest; |
|
68
|
|
|
|
|
|
|
my $lSubmitDate; |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if ( $self->{digest} eq "FAT" ) { |
|
71
|
0
|
|
|
|
|
|
$ldigest = "SHA2"; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
else { |
|
74
|
0
|
|
|
|
|
|
$ldigest = $self->{digest}; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
0
|
0
|
|
|
|
|
my $localDigest = _DigestAFile( "$filename", $ldigest ) |
|
77
|
|
|
|
|
|
|
or die "Unable to digest the file $filename"; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $SSubDir; |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if ( !( $self->{digest} eq "FAT" ) ) { |
|
82
|
0
|
|
|
|
|
|
my $localSubDir = substr( $localDigest, 0, 2 ); |
|
83
|
0
|
|
|
|
|
|
$SSubDir = $self->{path} . "/" . $localSubDir; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
else { |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$lSubmitDate = _SubmitDate(); |
|
89
|
0
|
|
|
|
|
|
$lSubmitDate =~ s/-/\//g; |
|
90
|
0
|
|
|
|
|
|
$SSubDir = $self->{path} . "/" . $self->{prefix} . "/" . $lSubmitDate; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
|
if ( !( -e $SSubDir ) ) { |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
mkpath($SSubDir) or die "Unable to create subdirectoris $SSubDir in the hstore"; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $destStoredFile = $SSubDir . "/" . $localDigest; |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
if ( !( $self->{digest} eq "FAT" ) ) { |
|
102
|
0
|
0
|
|
|
|
|
copy( $filename, $destStoredFile ) |
|
103
|
|
|
|
|
|
|
or die "Unable to copy file into hstore as $destStoredFile"; |
|
104
|
|
|
|
|
|
|
} else { |
|
105
|
0
|
|
|
|
|
|
mkpath($destStoredFile); |
|
106
|
0
|
|
|
|
|
|
copy( $filename, $destStoredFile); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
if ( !( $self->{digest} eq "FAT" ) ) { |
|
110
|
0
|
|
|
|
|
|
return $localDigest; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
else { |
|
113
|
0
|
|
|
|
|
|
$lSubmitDate =~ s/\//-/g; |
|
114
|
0
|
|
|
|
|
|
return $self->{prefix} . "-" . $lSubmitDate . "-" . $localDigest; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub remove { |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
|
|
0
|
1
|
|
my ( $self, $id ) = @_; |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $destStoredFile; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# if (!(defined($id))) {die "hash to be removed not defined";} |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
|
if ( !( defined($id) ) ) { return undef; } |
|
|
0
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
if ( !( $self->{digest} eq "FAT" ) ) { |
|
129
|
0
|
|
|
|
|
|
my $localSubDir = substr( $id, 0, 2 ); |
|
130
|
0
|
|
|
|
|
|
my $SSubDir = $self->{path} . "/" . $localSubDir; |
|
131
|
0
|
|
|
|
|
|
$destStoredFile = $SSubDir . "/" . $id; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
else { |
|
134
|
0
|
|
|
|
|
|
$id =~ s/-/\//g; |
|
135
|
0
|
|
|
|
|
|
$destStoredFile = $self->{path} . "/" . $id; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
if ( -e $destStoredFile ) { |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
|
if ( !( $self->{digest} eq "FAT" ) ) { |
|
141
|
0
|
0
|
|
|
|
|
unlink($destStoredFile) or return undef; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
else { |
|
144
|
0
|
0
|
|
|
|
|
rmtree($destStoredFile) or return undef; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
#die "Unable to delete file from hstore named $destStoredFile"; |
|
148
|
|
|
|
|
|
|
#return undef; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
else { |
|
151
|
0
|
|
|
|
|
|
return; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub getpath { |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
0
|
1
|
|
my ( $self, $id ) = @_; |
|
159
|
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
my $destStoredFile; |
|
161
|
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
|
if ( !( $self->{digest} eq "FAT" ) ) { |
|
163
|
0
|
|
|
|
|
|
my $localSubDir = substr( $id, 0, 2 ); |
|
164
|
0
|
|
|
|
|
|
my $SSubDir = $self->{path} . "/" . $localSubDir; |
|
165
|
0
|
|
|
|
|
|
$destStoredFile = $SSubDir . "/" . $id; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
else { |
|
168
|
0
|
|
|
|
|
|
$id =~ s/-/\//g; |
|
169
|
0
|
|
|
|
|
|
$destStoredFile = $self->{path} . "/" . $id; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
0
|
0
|
|
|
|
|
if ( -e $destStoredFile ) { |
|
173
|
0
|
|
|
|
|
|
return $destStoredFile; |
|
174
|
|
|
|
|
|
|
} else { |
|
175
|
0
|
|
|
|
|
|
return; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub _printPath { |
|
180
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
181
|
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
return $self->{path}; |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub _DigestAFile { |
|
187
|
|
|
|
|
|
|
|
|
188
|
0
|
|
|
0
|
|
|
my $file = shift; |
|
189
|
0
|
|
|
|
|
|
my $digestdef = shift; |
|
190
|
0
|
|
|
|
|
|
my $sha; |
|
191
|
0
|
0
|
|
|
|
|
open( FILED, "$file" ) or die "Unable to open file $file"; |
|
192
|
0
|
0
|
|
|
|
|
if ( $digestdef eq "SHA1" ) { |
|
|
|
0
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
$sha = Digest::SHA->new("sha1"); |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
elsif ( $digestdef eq "SHA2" ) { |
|
196
|
0
|
|
|
|
|
|
$sha = Digest::SHA->new("sha256"); |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
else { |
|
199
|
0
|
|
|
|
|
|
print "unknown digest method"; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
0
|
|
|
|
|
|
$sha->addfile(*FILED); |
|
202
|
0
|
|
|
|
|
|
close(FILED); |
|
203
|
0
|
|
|
|
|
|
return my $digest = $sha->hexdigest; |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
# Used only for the Free Archive Toolkit mixed-"hash" format |
|
208
|
|
|
|
|
|
|
# |
|
209
|
|
|
|
|
|
|
# FAT is following this format : |
|
210
|
|
|
|
|
|
|
# |
|
211
|
|
|
|
|
|
|
# prefix-year-mm-dd-hh-mm-ss-hash |
|
212
|
|
|
|
|
|
|
# |
|
213
|
|
|
|
|
|
|
# The format is represented on disk with the following format : |
|
214
|
|
|
|
|
|
|
# |
|
215
|
|
|
|
|
|
|
# prefix/year/mm/dd/hh/mm/ss/hash |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# return the date in FAT format |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub _SubmitDate { |
|
220
|
|
|
|
|
|
|
|
|
221
|
0
|
|
|
0
|
|
|
my ( $sec, $min, $hour, $day, $month, $year ) = |
|
222
|
|
|
|
|
|
|
(localtime)[ 0, 1, 2, 3, 4, 5 ]; |
|
223
|
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
return sprintf( |
|
225
|
|
|
|
|
|
|
"%04d-%02d-%02d-%02d-%02d-%02d", |
|
226
|
|
|
|
|
|
|
$year + 1900, |
|
227
|
|
|
|
|
|
|
$month + 1, $day, $hour, $min, $sec |
|
228
|
|
|
|
|
|
|
); |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
} |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
1; |
|
233
|
|
|
|
|
|
|
__END__ |