line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Smoke::FTPClient; |
2
|
1
|
|
|
1
|
|
16
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
70
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
10
|
use Net::FTP; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
142
|
|
5
|
1
|
|
|
1
|
|
19
|
use Cwd; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
124
|
|
6
|
1
|
|
|
1
|
|
13
|
use File::Path; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
125
|
|
7
|
1
|
|
|
1
|
|
17
|
use File::Spec::Functions qw( :DEFAULT abs2rel rel2abs ); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
349
|
|
8
|
1
|
|
|
1
|
|
13
|
use Test::Smoke::Util qw( clean_filename time_in_hhmm ); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
88
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
12
|
use vars qw( $VERSION ); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
193
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.011'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my %CONFIG = ( |
14
|
|
|
|
|
|
|
df_fserver => undef, |
15
|
|
|
|
|
|
|
df_fuser => 'anonymous', |
16
|
|
|
|
|
|
|
df_fpasswd => 'smokers@perl.org', |
17
|
|
|
|
|
|
|
df_v => 0, |
18
|
|
|
|
|
|
|
df_fpassive => 1, |
19
|
|
|
|
|
|
|
df_ftype => undef, |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
valid => [qw( fuser fpasswd fpassive ftype )], |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
my @sn = qw( B KB MB GB TB ); |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
162
|
BEGIN { eval qq/use Time::HiRes qw( time ) / } |
|
1
|
|
|
1
|
|
22
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
19
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 NAME |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Test::Smoke::FTPClient - Implement a mirror like object |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 SYNOPSIS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use Test::Smoke::FTPClient; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $server = 'ftp.linux.activestate.com'; |
36
|
|
|
|
|
|
|
my $fc = Test::Smoke::FTPClient->new( $server ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $sdir = '/pub/staff/gsar/APC/perl-current'; |
39
|
|
|
|
|
|
|
my $ddir = '~/perlsmoke/perl-current'; |
40
|
|
|
|
|
|
|
my $cleanup = 1; # like --delete for rsync |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$fc->connect; |
43
|
|
|
|
|
|
|
$fc->mirror( $sdir, $ddir, $cleanup ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$fc->bye; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 DESCRIPTION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
This module was written specifically to fetch a perl source-tree |
50
|
|
|
|
|
|
|
from the APC. It will not suffice as a general purpose mirror module! |
51
|
|
|
|
|
|
|
It only distinguishes between files and directories and relies on the |
52
|
|
|
|
|
|
|
output of the C<< Net::FTP->dir >> method. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This solution is B, you'd better use B! |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 Test::Smoke::FTPClient->new( $server[, %options] ) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Create a new object with option checking: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
* fuser |
63
|
|
|
|
|
|
|
* fpasswd |
64
|
|
|
|
|
|
|
* v |
65
|
|
|
|
|
|
|
* fpassive |
66
|
|
|
|
|
|
|
* ftype |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub new { |
71
|
3
|
|
|
3
|
1
|
15
|
my $class = shift; |
72
|
|
|
|
|
|
|
|
73
|
3
|
|
|
|
|
14
|
my $server = shift; |
74
|
|
|
|
|
|
|
|
75
|
3
|
50
|
|
|
|
9
|
unless ( $server ) { |
76
|
0
|
|
|
|
|
0
|
require Carp; |
77
|
0
|
|
|
|
|
0
|
Carp::croak( "Usage: Test::Smoke::FTPClient->new( \$server )" ); |
78
|
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
|
80
|
3
|
50
|
|
|
|
23
|
my %args_raw = @_ ? UNIVERSAL::isa( $_[0], 'HASH' ) ? %{ $_[0] } : @_ : (); |
|
3
|
50
|
|
|
|
25
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my %args = map { |
83
|
3
|
|
|
|
|
14
|
( my $key = $_ ) =~ s/^-?(.+)$/lc $1/e; |
|
15
|
|
|
|
|
75
|
|
|
15
|
|
|
|
|
65
|
|
84
|
15
|
|
|
|
|
57
|
( $key => $args_raw{ $_ } ); |
85
|
|
|
|
|
|
|
} keys %args_raw; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my %fields = map { |
88
|
15
|
100
|
|
|
|
41
|
my $value = exists $args{$_} ? $args{ $_ } : $CONFIG{ "df_$_" }; |
89
|
15
|
|
|
|
|
47
|
( $_ => $value ) |
90
|
3
|
|
|
|
|
9
|
} ( v => @{ $CONFIG{ valid } } ); |
|
3
|
|
|
|
|
10
|
|
91
|
3
|
|
|
|
|
8
|
$fields{fserver} = $server; |
92
|
3
|
|
50
|
|
|
27
|
$fields{v} ||= 0; |
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
|
|
18
|
return bless \%fields, $class; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 $ftpclient->connect( ) |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Returns true for success after connecting and login. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub connect { |
105
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
106
|
|
|
|
|
|
|
|
107
|
3
|
50
|
|
|
|
11
|
$self->{v} and print "Connecting to '$self->{fserver}' "; |
108
|
|
|
|
|
|
|
$self->{client} = Net::FTP->new( $self->{fserver}, |
109
|
|
|
|
|
|
|
Passive => $self->{fpassive}, |
110
|
3
|
|
|
|
|
57
|
Debug => ( $self->{v} > 2 ), |
111
|
|
|
|
|
|
|
); |
112
|
3
|
50
|
|
|
|
148
|
unless ( $self->{client} ) { |
113
|
0
|
|
|
|
|
0
|
$self->{error} = $@; |
114
|
0
|
0
|
|
|
|
0
|
$self->{v} and print "NOT OK ($self->{error})\n"; |
115
|
0
|
|
|
|
|
0
|
return; |
116
|
|
|
|
|
|
|
} |
117
|
3
|
50
|
|
|
|
7
|
$self->{v} and print "OK\n"; |
118
|
|
|
|
|
|
|
|
119
|
3
|
50
|
|
|
|
10
|
$self->{v} and print "Authenticating "; |
120
|
3
|
50
|
|
|
|
30
|
unless ( $self->{client}->login( $self->{fuser}, $self->{fpasswd} ) ) { |
121
|
0
|
|
0
|
|
|
0
|
$self->{error} = $@ || |
122
|
|
|
|
|
|
|
"Could not login($self->{fuser}) on $self->{fserver}"; |
123
|
0
|
0
|
|
|
|
0
|
$self->{v} and print "NOT OK ($self->{error})\n"; |
124
|
0
|
|
|
|
|
0
|
return; |
125
|
|
|
|
|
|
|
} |
126
|
3
|
50
|
|
|
|
17
|
$self->{v} and print "OK\n"; |
127
|
|
|
|
|
|
|
|
128
|
3
|
|
|
|
|
8
|
return 1; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 $client->mirror( $sdir, $ddir ) |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Set-up the environment and call C<__do_mirror()> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub mirror { |
138
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
139
|
3
|
50
|
|
|
|
24
|
return unless UNIVERSAL::isa( $self->{client}, 'Net::FTP' ); |
140
|
|
|
|
|
|
|
|
141
|
3
|
|
|
|
|
9
|
my( $fdir, $ddir, $cleanup ) = @_; |
142
|
3
|
|
|
|
|
12127
|
my $cwd = cwd(); |
143
|
|
|
|
|
|
|
# Get the local directory sorted |
144
|
3
|
|
|
|
|
109
|
$ddir = rel2abs( $ddir ); |
145
|
3
|
100
|
|
|
|
1054
|
mkpath( $ddir, $self->{v} ) unless -d $ddir; |
146
|
3
|
50
|
|
|
|
57
|
unless ( chdir $ddir ) { |
147
|
0
|
|
|
|
|
0
|
$self->{error} = "Cannot chdir($ddir): $!"; |
148
|
0
|
|
|
|
|
0
|
return; |
149
|
|
|
|
|
|
|
} |
150
|
3
|
|
|
|
|
35
|
my $lroot = catdir( $ddir, updir ); |
151
|
3
|
50
|
33
|
|
|
10469
|
chdir $lroot and $lroot = cwd() and chdir $cwd; |
152
|
|
|
|
|
|
|
|
153
|
3
|
50
|
33
|
|
|
55
|
if ( $self->{ftype} && $self->{client}->can( $self->{ftype} ) ) { |
154
|
0
|
|
|
|
|
0
|
my $ftype = $self->{ftype}; |
155
|
0
|
|
|
|
|
0
|
eval '$self->{client}->$ftype'; |
156
|
|
|
|
|
|
|
} |
157
|
3
|
|
|
|
|
31
|
my( $totsize, $tottime ) = ( 0, 0 ); |
158
|
3
|
50
|
|
|
|
37
|
$self->{v} and print "Start mirror to: $ddir\n"; |
159
|
3
|
|
|
|
|
24
|
my $start = time; |
160
|
|
|
|
|
|
|
my $ret = __do_mirror( $self->{client}, $fdir, $ddir, $lroot, |
161
|
3
|
|
|
|
|
51
|
$self->{v}, $cleanup, $totsize, $tottime ); |
162
|
3
|
|
|
|
|
33
|
my $ttime = time - $start; |
163
|
3
|
100
|
|
|
|
12
|
$tottime or $tottime = 0.001; |
164
|
3
|
|
|
|
|
9
|
my $speed = $totsize / $tottime; |
165
|
3
|
|
|
|
|
5
|
my $ord = 0; |
166
|
3
|
|
|
|
|
16
|
while ( $speed > 1024 ) { $speed /= 1024; $ord++ } |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
4
|
|
167
|
3
|
50
|
|
|
|
9
|
$self->{v} and printf "Mirror took %s \@ %.3f %s\n", |
168
|
|
|
|
|
|
|
time_in_hhmm( $ttime ), $speed, $sn[ $ord ]; |
169
|
3
|
|
|
|
|
26
|
chdir $cwd; |
170
|
3
|
|
|
|
|
61
|
return $ret; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 $client->bye |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Disconnect from the FTP-server and cleanup the Net::FTP client; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub bye { |
180
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
181
|
0
|
|
|
|
|
0
|
$self->{client}->quit; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 Test::Smoke::FTPClient->config( $key[, $value] ) |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
C is an interface to the package lexical C<%CONFIG>, |
187
|
|
|
|
|
|
|
which holds all the default values for the C arguments. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
With the special key B this returns a reference |
190
|
|
|
|
|
|
|
to a hash holding all the default values. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub config { |
195
|
0
|
|
|
0
|
1
|
0
|
my $dummy = shift; |
196
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
0
|
my $key = lc shift; |
198
|
|
|
|
|
|
|
|
199
|
0
|
0
|
|
|
|
0
|
if ( $key eq 'all_defaults' ) { |
200
|
|
|
|
|
|
|
my %default = map { |
201
|
0
|
|
|
|
|
0
|
my( $pass_key ) = $_ =~ /^df_(.+)/; |
|
0
|
|
|
|
|
0
|
|
202
|
0
|
|
|
|
|
0
|
( $pass_key => $CONFIG{ $_ } ); |
203
|
|
|
|
|
|
|
} grep /^df_/ => keys %CONFIG; |
204
|
0
|
|
|
|
|
0
|
return \%default; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
0
|
0
|
|
|
|
0
|
return undef unless exists $CONFIG{ "df_$key" }; |
208
|
|
|
|
|
|
|
|
209
|
0
|
0
|
|
|
|
0
|
$CONFIG{ "df_$key" } = shift if @_; |
210
|
|
|
|
|
|
|
|
211
|
0
|
|
|
|
|
0
|
return $CONFIG{ "df_$key" }; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 __do_mirror( $ftp, $ftpdir, $localdir, $lroot, $verbose, $cleanup ) |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Recursive sub to mirror a tree from an FTP server. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
{ |
221
|
|
|
|
|
|
|
my $mirror_ok = 1; |
222
|
|
|
|
|
|
|
sub __do_mirror { |
223
|
35
|
|
|
35
|
|
160
|
my( $ftp, $ftpdir, $localdir, $lroot, $verbose, $cleanup, |
224
|
|
|
|
|
|
|
$totsize, $tottime ) = @_; |
225
|
35
|
|
50
|
|
|
168
|
$verbose ||= 0; |
226
|
|
|
|
|
|
|
|
227
|
35
|
|
|
|
|
391
|
$ftp->cwd( $ftpdir ); |
228
|
35
|
50
|
|
|
|
777
|
$verbose > 1 and printf "Entering %s\n", $ftp->pwd; |
229
|
|
|
|
|
|
|
|
230
|
35
|
|
|
|
|
104
|
my @list = dirlist( $ftp, $verbose ); |
231
|
|
|
|
|
|
|
|
232
|
35
|
|
|
|
|
2586
|
foreach my $entry ( sort { $a->{type} cmp $b->{type} || |
233
|
203
|
50
|
|
|
|
528
|
$a->{name} cmp $b->{name} } @list ) { |
234
|
|
|
|
|
|
|
|
235
|
144
|
100
|
|
|
|
304
|
if ( $entry->{type} eq 'd' ) { |
236
|
108
|
100
|
|
|
|
385
|
$entry->{name} =~ m/^\.\.?$/ and next; |
237
|
38
|
|
|
|
|
288
|
my $new_locald = File::Spec->catdir( $localdir, $entry->{name} ); |
238
|
38
|
100
|
|
|
|
861
|
unless ( -d $new_locald ) { |
239
|
24
|
50
|
|
|
|
70
|
eval { mkpath( $new_locald, $verbose, $entry->{mode} ) } or |
|
24
|
|
|
|
|
3406
|
|
240
|
|
|
|
|
|
|
return; |
241
|
24
|
50
|
|
|
|
99
|
$@ and return; |
242
|
|
|
|
|
|
|
} |
243
|
38
|
|
|
|
|
433
|
chdir $new_locald; |
244
|
|
|
|
|
|
|
$mirror_ok &&= __do_mirror( $ftp, $entry->{name}, |
245
|
38
|
|
100
|
|
|
274
|
$new_locald, $lroot, $verbose, |
246
|
|
|
|
|
|
|
$cleanup, $totsize, $tottime ); |
247
|
38
|
|
33
|
|
|
170
|
$entry->{time} ||= $entry->{date}; |
248
|
38
|
|
|
|
|
618
|
utime $entry->{time}, $entry->{time}, $new_locald; |
249
|
38
|
|
|
|
|
230
|
$ftp->cwd( '..' ); |
250
|
38
|
|
|
|
|
1087
|
chdir File::Spec->updir; |
251
|
38
|
50
|
|
|
|
176
|
$verbose > 1 and print "Leaving '$entry->{name}' [$new_locald]\n"; |
252
|
|
|
|
|
|
|
} else { |
253
|
36
|
|
|
|
|
150
|
$entry->{time} = $ftp->mdtm( $entry->{name} ); #slow down |
254
|
36
|
|
|
|
|
1409
|
my $fname = clean_filename( $entry->{name} ); |
255
|
|
|
|
|
|
|
|
256
|
36
|
|
|
|
|
190
|
my $destname = catfile( $localdir, canonpath($fname) ); |
257
|
|
|
|
|
|
|
|
258
|
36
|
|
|
|
|
69
|
my $skip; |
259
|
36
|
100
|
|
|
|
625
|
if ( -e $destname ) { |
260
|
17
|
|
|
|
|
239
|
my( $l_size, $l_mode, $l_time ) = (stat $destname)[7, 2, 9]; |
261
|
17
|
|
|
|
|
53
|
$l_mode &= 07777; |
262
|
|
|
|
|
|
|
$skip = ($l_size == $entry->{size}) && |
263
|
|
|
|
|
|
|
($l_mode == $entry->{mode}) && |
264
|
17
|
|
33
|
|
|
514
|
($l_time == $entry->{time}); |
265
|
|
|
|
|
|
|
} |
266
|
36
|
100
|
|
|
|
99
|
unless ( $skip ) { |
267
|
19
|
|
|
|
|
184
|
1 while unlink $destname; |
268
|
|
|
|
|
|
|
$verbose and printf "%s: %d/", abs2rel( $destname, $lroot ), |
269
|
19
|
50
|
|
|
|
49
|
$entry->{size}; |
270
|
19
|
|
|
|
|
56
|
my $start = time; |
271
|
19
|
|
|
|
|
85
|
my $dest = $ftp->get( $entry->{name}, $destname ); |
272
|
19
|
|
|
|
|
3580
|
my $t_time = time - $start; |
273
|
19
|
100
|
|
|
|
77
|
$dest or $mirror_ok = 0, return; |
274
|
|
|
|
|
|
|
|
275
|
17
|
50
|
|
|
|
32
|
$t_time or $t_time = 0.001; # avoid div by zero |
276
|
17
|
|
|
|
|
239
|
my $size = -s $dest; |
277
|
17
|
|
|
|
|
38
|
$totsize += $size; |
278
|
17
|
|
|
|
|
27
|
$tottime += $t_time; |
279
|
17
|
|
|
|
|
37
|
my $speed = $size / $t_time; |
280
|
17
|
|
|
|
|
26
|
my $ord = 0; |
281
|
17
|
|
|
|
|
47
|
while ( $speed > 1024 ) { $speed /= 1024; $ord++ } |
|
22
|
|
|
|
|
29
|
|
|
22
|
|
|
|
|
46
|
|
282
|
17
|
50
|
|
|
|
38
|
my $dig = $ord ? '3' : '0'; |
283
|
|
|
|
|
|
|
|
284
|
17
|
|
|
|
|
261
|
utime $entry->{time}, $entry->{time}, $dest; |
285
|
17
|
|
|
|
|
265
|
chmod $entry->{mode}, $dest; |
286
|
17
|
50
|
|
|
|
77
|
$verbose and printf "$size (%.${dig}f $sn[$ord]/s)\n", |
287
|
|
|
|
|
|
|
$speed; |
288
|
|
|
|
|
|
|
} else { |
289
|
|
|
|
|
|
|
$verbose > 1 and |
290
|
|
|
|
|
|
|
printf "%s: %d/skipped\n", abs2rel( $destname, $lroot), |
291
|
17
|
50
|
|
|
|
57
|
$entry->{size}; |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
} |
295
|
33
|
50
|
|
|
|
65
|
if ( $cleanup ) { |
296
|
33
|
|
|
|
|
288
|
chdir $localdir; |
297
|
33
|
50
|
|
|
|
98
|
$verbose > 1 and print "Cleanup '$localdir'\n"; |
298
|
|
|
|
|
|
|
my %ok_file = map { |
299
|
33
|
|
|
|
|
73
|
( clean_filename( $_->{name} ) => $_->{type} ) |
300
|
132
|
|
|
|
|
293
|
} @list; |
301
|
33
|
|
|
|
|
138
|
local *DIR; |
302
|
33
|
50
|
|
|
|
718
|
if ( opendir DIR, '.' ) { |
303
|
33
|
|
|
|
|
693
|
foreach ( readdir DIR ) { |
304
|
134
|
|
|
|
|
430
|
my $cmpname = clean_filename( $_ ); |
305
|
134
|
50
|
|
|
|
299
|
$^O eq 'VMS' and $cmpname =~ s/\.$//; |
306
|
134
|
100
|
66
|
|
|
2525
|
if( -f $cmpname ) { |
|
|
100
|
|
|
|
|
|
307
|
36
|
100
|
66
|
|
|
217
|
unless ( exists $ok_file{ $cmpname } && |
308
|
|
|
|
|
|
|
$ok_file{ $cmpname } eq 'f' ) { |
309
|
2
|
50
|
|
|
|
10
|
$verbose and printf "Delete %s\n", |
310
|
|
|
|
|
|
|
abs2rel( rel2abs( $cmpname ), |
311
|
|
|
|
|
|
|
$lroot ); |
312
|
2
|
|
|
|
|
164
|
1 while unlink $_; |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
} elsif ( -d && ! /^..?\z/ ) { |
315
|
19
|
50
|
|
|
|
65
|
$^O eq 'VMS' and $cmpname =~ s/\.DIR$//i; |
316
|
19
|
50
|
33
|
|
|
87
|
unless ( exists $ok_file{ $cmpname } && |
317
|
|
|
|
|
|
|
$ok_file{ $cmpname } eq 'd' ) { |
318
|
0
|
|
|
|
|
0
|
rmtree( $cmpname, $verbose ); |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
} |
322
|
33
|
|
|
|
|
439
|
closedir DIR; |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
} |
325
|
33
|
|
|
|
|
130
|
@_[ -2, -1 ] = ( $totsize, $tottime ); |
326
|
33
|
|
|
|
|
188
|
return $mirror_ok; |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
=head2 dirlist( $ftp, $verbose ) |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
Return a list of entries (hashrefs) with these properties: |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
* name: Filename |
335
|
|
|
|
|
|
|
* type f/d/l |
336
|
|
|
|
|
|
|
* mode unix file mode |
337
|
|
|
|
|
|
|
* size filessize in bytes |
338
|
|
|
|
|
|
|
* date file date |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=cut |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
sub dirlist { |
343
|
35
|
|
|
35
|
1
|
74
|
my( $ftp, $verbose ) = @_; |
344
|
35
|
|
|
|
|
140
|
map __parse_line_from_dir( $_, $verbose ) => $ftp->dir; |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=head2 __parse_line_from_dir( $line, $verbose ) |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
The C command in FTP gives a sort of C output, |
350
|
|
|
|
|
|
|
parts of this output are used as remote file-info. |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=cut |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
sub __parse_line_from_dir { |
355
|
147
|
|
|
147
|
|
25991
|
my( $entry, $verbose ) = @_; |
356
|
147
|
|
|
|
|
569
|
my @field = split " ", $entry; |
357
|
|
|
|
|
|
|
|
358
|
147
|
50
|
|
|
|
698
|
if ( $field[0] =~ /[dwrx-]{7}/ ) { # Unixy dir entry |
359
|
|
|
|
|
|
|
|
360
|
147
|
|
|
|
|
445
|
( my $type = substr $field[0], 0, 1 ) =~ tr/-/f/; |
361
|
|
|
|
|
|
|
return { |
362
|
147
|
|
|
|
|
461
|
name => $field[-1], |
363
|
|
|
|
|
|
|
type => $type, |
364
|
|
|
|
|
|
|
mode => __get_mode_from_text( substr $field[0], 1 ), |
365
|
|
|
|
|
|
|
size => $field[4], |
366
|
|
|
|
|
|
|
time => 0, |
367
|
|
|
|
|
|
|
date => __time_from_ls( @field[5, 6, 7] ), |
368
|
|
|
|
|
|
|
} |
369
|
|
|
|
|
|
|
} else { # Windowsy dir entry |
370
|
0
|
0
|
|
|
|
0
|
my $type = $field[2] eq '' ? 'd' : 'f'; |
371
|
|
|
|
|
|
|
return { |
372
|
0
|
|
|
|
|
0
|
name => $field[-1], |
373
|
|
|
|
|
|
|
type => $type, |
374
|
|
|
|
|
|
|
mode => 0777, |
375
|
|
|
|
|
|
|
size => $field[2], |
376
|
|
|
|
|
|
|
time => 0, |
377
|
|
|
|
|
|
|
date => __time_from_windows( @field[0, 1] ), |
378
|
|
|
|
|
|
|
} |
379
|
|
|
|
|
|
|
} |
380
|
|
|
|
|
|
|
} |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
=head2 __get_mode_from_text( $tmode ) |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
This takes the text representation of a file-mode (like 'rwxr--r--') |
385
|
|
|
|
|
|
|
and return the numeric value. |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
=cut |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
sub __get_mode_from_text { |
390
|
147
|
|
|
147
|
|
495
|
my( $tmode ) = @_; # nine letter/dash |
391
|
|
|
|
|
|
|
|
392
|
147
|
|
|
|
|
211
|
$tmode =~ tr/rwx-/1110/; |
393
|
147
|
|
|
|
|
236
|
my $mode = 0; |
394
|
147
|
|
|
|
|
372
|
for ( my $i = 0; $i < 3; $i++ ) { |
395
|
441
|
|
|
|
|
629
|
$mode <<= 3; |
396
|
441
|
|
|
|
|
1164
|
$mode += ord(pack B3 => substr $tmode, $i*3, 3) >> 5; |
397
|
|
|
|
|
|
|
} |
398
|
|
|
|
|
|
|
|
399
|
147
|
|
|
|
|
443
|
return $mode; |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
=head2 __time_from_ls( $mname, $day, $time_or_year ) |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
This takes the three date/time related columns from the C output |
405
|
|
|
|
|
|
|
and returns a localtime-stamp. |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
=cut |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
sub __time_from_ls { |
410
|
147
|
|
|
147
|
|
325
|
my( $mname, $day, $time_or_year ) = @_; |
411
|
|
|
|
|
|
|
|
412
|
147
|
|
|
|
|
2593
|
my( $local_year, $local_month) = (localtime)[5, 4]; |
413
|
147
|
|
|
|
|
452
|
$local_year += 1900; |
414
|
|
|
|
|
|
|
|
415
|
147
|
|
|
|
|
405
|
my $month = int( index('JanFebMarAprMayJunJulAugSepOctNovDec', $mname)/3 ); |
416
|
|
|
|
|
|
|
|
417
|
147
|
50
|
|
|
|
616
|
my( $year, $time ) = $time_or_year =~ /:/ |
|
|
100
|
|
|
|
|
|
418
|
|
|
|
|
|
|
? $month > $local_month ? ( $local_year - 1, $time_or_year ) : |
419
|
|
|
|
|
|
|
($local_year, $time_or_year) : ($time_or_year, '00:00' ); |
420
|
|
|
|
|
|
|
|
421
|
147
|
|
|
|
|
854
|
my( $hour, $minutes ) = $time =~ /(\d+):(\d+)/; |
422
|
|
|
|
|
|
|
|
423
|
147
|
|
|
|
|
811
|
require Time::Local; |
424
|
147
|
|
|
|
|
550
|
return Time::Local::timelocal( 0, $minutes, $hour, $day, $month, $year ); |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
=head2 __time_from_windows( $date, $time ) |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
This takes the two date/time related columns from the C output |
430
|
|
|
|
|
|
|
and returns a localtime-stamp |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
=cut |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
sub __time_from_windows { |
435
|
0
|
|
|
0
|
|
|
my( $date, $time ) = @_; |
436
|
|
|
|
|
|
|
|
437
|
0
|
|
|
|
|
|
my( $day, $month, $year ) = split m/-/, $date; |
438
|
0
|
|
|
|
|
|
$month--; |
439
|
0
|
|
|
|
|
|
my( $hour, $minutes, $off ) = $time =~ m/(\d+):(\d+)([ap])m/i; |
440
|
0
|
0
|
0
|
|
|
|
$off && lc $off eq 'p' and $hour += 12; |
441
|
|
|
|
|
|
|
|
442
|
0
|
|
|
|
|
|
require Time::Local; |
443
|
0
|
|
|
|
|
|
return Time::Local::timelocal( 0, $minutes, $hour, $day, $month, $year ); |
444
|
|
|
|
|
|
|
} |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
1; |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
=head1 SEE ALSO |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
L |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
(c) 2003, 2004, 2005, Abe Timmerman All rights reserved. |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
457
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
See: |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
* , |
462
|
|
|
|
|
|
|
* |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
465
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
466
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
=cut |