line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#*** UploadMirror.pm ***#
|
2
|
|
|
|
|
|
|
# Copyright (C) 2005 - 2008 by Torsten Knorr
|
3
|
|
|
|
|
|
|
# create-soft@tiscali.de
|
4
|
|
|
|
|
|
|
# All rights reserved!
|
5
|
|
|
|
|
|
|
#-------------------------------------------------
|
6
|
1
|
|
|
1
|
|
48304
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
60
|
|
7
|
|
|
|
|
|
|
#------------------------------------------------
|
8
|
|
|
|
|
|
|
package Net::UploadMirror::FileName;
|
9
|
1
|
|
|
1
|
|
43568
|
use Storable;
|
|
1
|
|
|
|
|
4757
|
|
|
1
|
|
|
|
|
261
|
|
10
|
2
|
|
33
|
2
|
|
5
|
sub TIESCALAR{ my ($class, $obj) = @_; return bless(\$obj, $class || ref($class)); }
|
|
2
|
|
|
|
|
33
|
|
11
|
|
|
|
|
|
|
sub STORE
|
12
|
|
|
|
|
|
|
{
|
13
|
4
|
100
|
|
4
|
|
856
|
if(-f $_[1])
|
14
|
|
|
|
|
|
|
{
|
15
|
2
|
|
|
|
|
16
|
${$_[0]}->{_last_modified} = retrieve($_[1]);
|
|
2
|
|
|
|
|
329
|
|
16
|
|
|
|
|
|
|
}
|
17
|
|
|
|
|
|
|
else
|
18
|
|
|
|
|
|
|
{
|
19
|
2
|
|
|
|
|
5
|
${$_[0]}->{_last_modified} = {};
|
|
2
|
|
|
|
|
13
|
|
20
|
2
|
|
|
|
|
7
|
store(${$_[0]}->{_last_modified}, $_[1]);
|
|
2
|
|
|
|
|
11
|
|
21
|
2
|
|
|
|
|
849
|
warn("\nno information of the files last modified times\n");
|
22
|
|
|
|
|
|
|
}
|
23
|
|
|
|
|
|
|
}
|
24
|
5
|
|
|
5
|
|
672
|
sub FETCH { return ${$_[0]}->{_filename}; }
|
|
5
|
|
|
|
|
31
|
|
25
|
|
|
|
|
|
|
#-------------------------------------------------
|
26
|
|
|
|
|
|
|
package Net::UploadMirror;
|
27
|
|
|
|
|
|
|
#-------------------------------------------------
|
28
|
1
|
|
|
1
|
|
1217
|
use Net::MirrorDir 0.19;
|
|
1
|
|
|
|
|
136709
|
|
|
1
|
|
|
|
|
29
|
|
29
|
1
|
|
|
1
|
|
11
|
use Storable;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
93
|
|
30
|
1
|
|
|
1
|
|
6
|
use vars '$AUTOLOAD';
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7423
|
|
31
|
|
|
|
|
|
|
#------------------------------------------------
|
32
|
|
|
|
|
|
|
@Net::UploadMirror::ISA = qw(Net::MirrorDir);
|
33
|
|
|
|
|
|
|
$Net::UploadMirror::VERSION = '0.13';
|
34
|
|
|
|
|
|
|
#-------------------------------------------------
|
35
|
|
|
|
|
|
|
sub _Init
|
36
|
|
|
|
|
|
|
{
|
37
|
2
|
|
|
2
|
|
18871
|
my ($self, %arg) = @_;
|
38
|
2
|
|
|
|
|
17
|
tie($self->{_filename}, 'Net::UploadMirror::FileName', $self);
|
39
|
2
|
|
50
|
|
|
23
|
$self->{_filename} = $arg{filename} || 'lastmodified_local';
|
40
|
2
|
|
50
|
|
|
20
|
$self->{_delete} = $arg{delete} || 'disabled';
|
41
|
2
|
|
|
|
|
11
|
return 1;
|
42
|
|
|
|
|
|
|
}
|
43
|
|
|
|
|
|
|
#-------------------------------------------------
|
44
|
|
|
|
|
|
|
sub Upload
|
45
|
|
|
|
|
|
|
{
|
46
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_;
|
47
|
0
|
0
|
|
|
|
0
|
return 0 unless($self->Connect());
|
48
|
0
|
|
|
|
|
0
|
my ($rh_lf, $rh_ld) = $self->ReadLocalDir();
|
49
|
0
|
0
|
|
|
|
0
|
if($self->{_debug})
|
50
|
|
|
|
|
|
|
{
|
51
|
0
|
|
|
|
|
0
|
print("local files : $_\n") for(sort keys %$rh_lf);
|
52
|
0
|
|
|
|
|
0
|
print("local dirs : $_\n") for(sort keys %$rh_ld);
|
53
|
|
|
|
|
|
|
}
|
54
|
0
|
|
|
|
|
0
|
my ($rh_rf, $rh_rd) = $self->ReadRemoteDir();
|
55
|
0
|
0
|
|
|
|
0
|
if($self->{_debug})
|
56
|
|
|
|
|
|
|
{
|
57
|
0
|
|
|
|
|
0
|
print("remote files : $_\n") for(sort keys %$rh_rf);
|
58
|
0
|
|
|
|
|
0
|
print("remote dirs : $_\n") for(sort keys %$rh_rd);
|
59
|
|
|
|
|
|
|
}
|
60
|
0
|
|
|
|
|
0
|
my $ra_ldnir = $self->LocalNotInRemote($rh_ld, $rh_rd);
|
61
|
0
|
0
|
|
|
|
0
|
if($self->{_debug})
|
62
|
|
|
|
|
|
|
{
|
63
|
0
|
|
|
|
|
0
|
print("local directories not in remote : $_\n") for(@$ra_ldnir);
|
64
|
|
|
|
|
|
|
}
|
65
|
0
|
|
|
|
|
0
|
$self->MakeDirs($ra_ldnir);
|
66
|
0
|
|
|
|
|
0
|
my $ra_lfnir = $self->LocalNotInRemote($rh_lf, $rh_rf);
|
67
|
0
|
0
|
|
|
|
0
|
if($self->{_debug})
|
68
|
|
|
|
|
|
|
{
|
69
|
0
|
|
|
|
|
0
|
print("local files not in remote: $_\n") for(@$ra_lfnir);
|
70
|
|
|
|
|
|
|
}
|
71
|
0
|
|
|
|
|
0
|
$self->StoreFiles($ra_lfnir);
|
72
|
0
|
0
|
|
|
|
0
|
if($self->{_delete} eq 'enable')
|
73
|
|
|
|
|
|
|
{
|
74
|
0
|
|
|
|
|
0
|
my $ra_rfnil = $self->RemoteNotInLocal($rh_lf, $rh_rf);
|
75
|
0
|
0
|
|
|
|
0
|
if($self->{_debug})
|
76
|
|
|
|
|
|
|
{
|
77
|
0
|
|
|
|
|
0
|
print("remote files not in local : $_\n") for(@$ra_rfnil);
|
78
|
|
|
|
|
|
|
}
|
79
|
0
|
|
|
|
|
0
|
$self->DeleteFiles($ra_rfnil);
|
80
|
0
|
|
|
|
|
0
|
my $ra_rdnil = $self->RemoteNotInLocal($rh_ld, $rh_rd);
|
81
|
0
|
0
|
|
|
|
0
|
if($self->{_debug})
|
82
|
|
|
|
|
|
|
{
|
83
|
0
|
|
|
|
|
0
|
print("remote directories not in local : $_\n") for(@$ra_rdnil);
|
84
|
|
|
|
|
|
|
}
|
85
|
0
|
|
|
|
|
0
|
$self->RemoveDirs($ra_rdnil);
|
86
|
|
|
|
|
|
|
}
|
87
|
0
|
|
|
|
|
0
|
delete(@{$rh_lf}{@$ra_lfnir});
|
|
0
|
|
|
|
|
0
|
|
88
|
0
|
|
|
|
|
0
|
my $ra_mlf = $self->CheckIfModified($rh_lf);
|
89
|
0
|
0
|
|
|
|
0
|
if($self->{_debug})
|
90
|
|
|
|
|
|
|
{
|
91
|
0
|
|
|
|
|
0
|
print("modified files : $_\n") for(@$ra_mlf);
|
92
|
|
|
|
|
|
|
}
|
93
|
0
|
|
|
|
|
0
|
$self->StoreFiles($ra_mlf);
|
94
|
0
|
|
|
|
|
0
|
$self->Quit();
|
95
|
0
|
|
|
|
|
0
|
return 1;
|
96
|
|
|
|
|
|
|
}
|
97
|
|
|
|
|
|
|
#-------------------------------------------------
|
98
|
|
|
|
|
|
|
sub CheckIfModified
|
99
|
|
|
|
|
|
|
{
|
100
|
1
|
|
|
1
|
1
|
3
|
my ($self, $rh_lf) = @_;
|
101
|
1
|
|
|
|
|
2
|
my @mf;
|
102
|
1
|
|
|
|
|
2
|
my $changed = undef;
|
103
|
1
|
|
|
|
|
5
|
for my $lf (keys(%$rh_lf))
|
104
|
|
|
|
|
|
|
{
|
105
|
0
|
0
|
|
|
|
0
|
next unless(-f $lf);
|
106
|
0
|
0
|
|
|
|
0
|
if(defined($self->{_last_modified}{$lf}))
|
107
|
|
|
|
|
|
|
{
|
108
|
0
|
0
|
|
|
|
0
|
next if($self->{_last_modified}{$lf} eq (stat($lf))[9]);
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
else
|
111
|
|
|
|
|
|
|
{
|
112
|
0
|
|
|
|
|
0
|
$self->{_last_modified}{$lf} = (stat($lf))[9];
|
113
|
0
|
|
|
|
|
0
|
$changed++;
|
114
|
|
|
|
|
|
|
}
|
115
|
0
|
|
|
|
|
0
|
push(@mf, $lf);
|
116
|
|
|
|
|
|
|
}
|
117
|
1
|
50
|
|
|
|
6
|
store($self->{_last_modified}, $self->{_filename}) if($changed);
|
118
|
1
|
|
|
|
|
5
|
return \@mf;
|
119
|
|
|
|
|
|
|
}
|
120
|
|
|
|
|
|
|
#-------------------------------------------------
|
121
|
|
|
|
|
|
|
sub UpdateLastModified
|
122
|
|
|
|
|
|
|
{
|
123
|
2
|
|
|
2
|
1
|
411
|
my ($self, $ra_lf) = @_;
|
124
|
2
|
|
|
|
|
8
|
for(@$ra_lf)
|
125
|
|
|
|
|
|
|
{
|
126
|
3
|
50
|
|
|
|
40
|
next unless(-e $_);
|
127
|
3
|
|
|
|
|
47
|
$self->{_last_modified}{$_} = (stat($_))[9];
|
128
|
|
|
|
|
|
|
}
|
129
|
2
|
|
|
|
|
36
|
store($self->{_last_modified}, $self->{_filename});
|
130
|
2
|
|
|
|
|
559
|
return 1;
|
131
|
|
|
|
|
|
|
}
|
132
|
|
|
|
|
|
|
#-------------------------------------------------
|
133
|
|
|
|
|
|
|
sub StoreFiles
|
134
|
|
|
|
|
|
|
{
|
135
|
1
|
|
|
1
|
1
|
3
|
my ($self, $ra_lf) = @_;
|
136
|
1
|
50
|
33
|
|
|
10
|
return 0 unless(@$ra_lf && $self->IsConnection());
|
137
|
0
|
|
|
|
|
0
|
my $rf;
|
138
|
0
|
|
|
|
|
0
|
for my $lf (@$ra_lf)
|
139
|
|
|
|
|
|
|
{
|
140
|
0
|
0
|
|
|
|
0
|
if(-f $lf)
|
141
|
|
|
|
|
|
|
{
|
142
|
0
|
|
|
|
|
0
|
$rf = $lf;
|
143
|
0
|
|
|
|
|
0
|
$rf =~ s!$self->{_regex_localdir}!$self->{_remotedir}!;
|
144
|
0
|
0
|
|
|
|
0
|
$self->{_last_modified}{$lf} = (stat($lf))[9] if($self->{_connection}->put($lf, $rf));
|
145
|
|
|
|
|
|
|
}
|
146
|
|
|
|
|
|
|
else
|
147
|
|
|
|
|
|
|
{
|
148
|
0
|
|
|
|
|
0
|
warn("error in StoreFiles() : $lf is not a local file\n");
|
149
|
|
|
|
|
|
|
}
|
150
|
|
|
|
|
|
|
}
|
151
|
0
|
|
|
|
|
0
|
store($self->{_last_modified}, $self->{_filename});
|
152
|
0
|
|
|
|
|
0
|
return 1;
|
153
|
|
|
|
|
|
|
}
|
154
|
|
|
|
|
|
|
#-------------------------------------------------
|
155
|
|
|
|
|
|
|
sub MakeDirs
|
156
|
|
|
|
|
|
|
{
|
157
|
1
|
|
|
1
|
1
|
3
|
my ($self, $ra_ld) = @_;
|
158
|
1
|
50
|
33
|
|
|
8
|
return 0 unless(@$ra_ld && $self->IsConnection());
|
159
|
0
|
|
|
|
|
0
|
my $rd;
|
160
|
0
|
|
|
|
|
0
|
for my $ld (@$ra_ld)
|
161
|
|
|
|
|
|
|
{
|
162
|
0
|
|
|
|
|
0
|
$rd = $ld;
|
163
|
0
|
0
|
|
|
|
0
|
if(-d $ld)
|
164
|
|
|
|
|
|
|
{
|
165
|
0
|
|
|
|
|
0
|
$rd =~ s!$self->{_regex_localdir}!$self->{_remotedir}!;
|
166
|
0
|
|
|
|
|
0
|
$self->{_connection}->mkdir($rd, 1) ;
|
167
|
|
|
|
|
|
|
}
|
168
|
|
|
|
|
|
|
else
|
169
|
|
|
|
|
|
|
{
|
170
|
0
|
|
|
|
|
0
|
warn("error in MakeDirs() : $rd is not a local directory\n");
|
171
|
|
|
|
|
|
|
}
|
172
|
|
|
|
|
|
|
}
|
173
|
0
|
|
|
|
|
0
|
return 1;
|
174
|
|
|
|
|
|
|
}
|
175
|
|
|
|
|
|
|
#-------------------------------------------------
|
176
|
|
|
|
|
|
|
sub DeleteFiles
|
177
|
|
|
|
|
|
|
{
|
178
|
1
|
|
|
1
|
1
|
3
|
my ($self, $ra_rf) = @_;
|
179
|
1
|
0
|
33
|
|
|
10
|
return 0 unless(
|
|
|
|
33
|
|
|
|
|
180
|
|
|
|
|
|
|
@$ra_rf
|
181
|
|
|
|
|
|
|
&& ($self->{_delete} eq 'enable')
|
182
|
|
|
|
|
|
|
&& $self->IsConnection()
|
183
|
|
|
|
|
|
|
);
|
184
|
0
|
|
|
|
|
0
|
my $lf;
|
185
|
0
|
|
|
|
|
0
|
for my $rf (@$ra_rf)
|
186
|
|
|
|
|
|
|
{
|
187
|
0
|
|
|
|
|
0
|
$lf = $rf;
|
188
|
0
|
|
|
|
|
0
|
$self->{_connection}->delete($rf);
|
189
|
0
|
|
|
|
|
0
|
$lf =~ s!$self->{_regex_remotedir}!$self->{_localdir}!;
|
190
|
0
|
0
|
|
|
|
0
|
delete($self->{_last_modified}{$lf}) if(defined($self->{_last_modified}{$lf}));
|
191
|
|
|
|
|
|
|
}
|
192
|
0
|
|
|
|
|
0
|
store($self->{_last_modified}, $self->{_filename});
|
193
|
0
|
|
|
|
|
0
|
return 1;
|
194
|
|
|
|
|
|
|
}
|
195
|
|
|
|
|
|
|
#-------------------------------------------------
|
196
|
|
|
|
|
|
|
sub RemoveDirs
|
197
|
|
|
|
|
|
|
{
|
198
|
1
|
|
|
1
|
1
|
3
|
my ($self, $ra_rd) = @_;
|
199
|
1
|
0
|
33
|
|
|
10
|
return 0 unless(
|
|
|
|
33
|
|
|
|
|
200
|
|
|
|
|
|
|
@$ra_rd
|
201
|
|
|
|
|
|
|
&& ($self->{_delete} eq 'enable')
|
202
|
|
|
|
|
|
|
&& $self->IsConnection()
|
203
|
|
|
|
|
|
|
);
|
204
|
0
|
|
|
|
|
0
|
$self->{_connection}->rmdir($_, 1) for(@$ra_rd);
|
205
|
0
|
|
|
|
|
0
|
return 1;
|
206
|
|
|
|
|
|
|
}
|
207
|
|
|
|
|
|
|
#-------------------------------------------------
|
208
|
|
|
|
|
|
|
sub CleanUp
|
209
|
|
|
|
|
|
|
{
|
210
|
1
|
|
|
1
|
1
|
424
|
my ($self, $ra_exists) = @_;
|
211
|
1
|
|
|
|
|
5
|
my %h_temp = ();
|
212
|
1
|
|
|
|
|
3
|
for my $key (@$ra_exists)
|
213
|
|
|
|
|
|
|
{
|
214
|
3
|
100
|
100
|
|
|
28
|
if(
|
215
|
|
|
|
|
|
|
defined($self->{_last_modified}{$key})
|
216
|
|
|
|
|
|
|
&&
|
217
|
|
|
|
|
|
|
($self->{_last_modified}{$key} =~ m/^\d+$/)
|
218
|
|
|
|
|
|
|
)
|
219
|
|
|
|
|
|
|
{
|
220
|
1
|
|
|
|
|
5
|
$h_temp{$key} = delete($self->{_last_modified}{$key});
|
221
|
|
|
|
|
|
|
}
|
222
|
|
|
|
|
|
|
}
|
223
|
1
|
50
|
|
|
|
5
|
if($self->{_debug})
|
224
|
|
|
|
|
|
|
{
|
225
|
1
|
|
|
|
|
509
|
print(
|
226
|
|
|
|
|
|
|
"key: $_ value: "
|
227
|
|
|
|
|
|
|
. (defined($self->{_last_modified}{$_}) ? $self->{_last_modified}{$_} : 'undef')
|
228
|
|
|
|
|
|
|
. " removed\n")
|
229
|
1
|
100
|
|
|
|
2
|
for(keys(%{$self->{_last_modified}}));
|
230
|
|
|
|
|
|
|
}
|
231
|
1
|
|
|
|
|
5
|
%{$self->{_last_modified}} = %h_temp;
|
|
1
|
|
|
|
|
5
|
|
232
|
1
|
|
|
|
|
8
|
store($self->{_last_modified}, $self->{_filename});
|
233
|
1
|
|
|
|
|
2684
|
return 1;
|
234
|
|
|
|
|
|
|
}
|
235
|
|
|
|
|
|
|
#-------------------------------------------------
|
236
|
|
|
|
|
|
|
sub LtoR
|
237
|
|
|
|
|
|
|
{
|
238
|
1
|
|
|
1
|
1
|
852
|
my ($self, $ra_lp) = @_;
|
239
|
1
|
|
|
|
|
3
|
my $ra_rp = [];
|
240
|
1
|
|
|
|
|
2
|
my $rp;
|
241
|
1
|
|
|
|
|
5
|
for(@$ra_lp)
|
242
|
|
|
|
|
|
|
{
|
243
|
3
|
|
|
|
|
6
|
$rp = $_;
|
244
|
3
|
|
|
|
|
22
|
$rp =~ s!$self->{_regex_localdir}!$self->{_remotedir}!;
|
245
|
3
|
|
|
|
|
26
|
push(@$ra_rp, $rp);
|
246
|
|
|
|
|
|
|
}
|
247
|
1
|
|
|
|
|
6
|
return $ra_rp;
|
248
|
|
|
|
|
|
|
}
|
249
|
|
|
|
|
|
|
#-------------------------------------------------
|
250
|
|
|
|
|
|
|
sub RtoL
|
251
|
|
|
|
|
|
|
{
|
252
|
1
|
|
|
1
|
1
|
3481
|
my ($self, $ra_rp) = @_;
|
253
|
1
|
|
|
|
|
4
|
my $ra_lp = [];
|
254
|
1
|
|
|
|
|
3
|
my $lp;
|
255
|
1
|
|
|
|
|
4
|
for(@$ra_rp)
|
256
|
|
|
|
|
|
|
{
|
257
|
3
|
|
|
|
|
5
|
$lp = $_;
|
258
|
3
|
|
|
|
|
32
|
$lp =~ s!$self->{_regex_remotedir}!$self->{_localdir}!;
|
259
|
3
|
|
|
|
|
27
|
push(@$ra_lp, $lp);
|
260
|
|
|
|
|
|
|
}
|
261
|
1
|
|
|
|
|
8
|
return $ra_lp;
|
262
|
|
|
|
|
|
|
}
|
263
|
|
|
|
|
|
|
#-------------------------------------------------
|
264
|
|
|
|
|
|
|
1;
|
265
|
|
|
|
|
|
|
#------------------------------------------------
|
266
|
|
|
|
|
|
|
__END__
|