4 |
use strict; |
use strict; |
5 |
use autodie; |
use autodie; |
6 |
|
|
7 |
|
use Data::Dump qw/dump/; |
8 |
use LWP::Simple qw/mirror RC_NOT_MODIFIED/; |
use LWP::Simple qw/mirror RC_NOT_MODIFIED/; |
9 |
use Storable; |
use Storable; |
10 |
use server; |
use server; |
11 |
|
|
12 |
sub mirror_file { |
sub mirror_file { |
13 |
my ( $url, $file ) = @_; |
my ( $url, $file ) = @_; |
14 |
print STDERR "mirror $url"; |
warn "mirror_file $url -> $file\n"; |
15 |
mirror( $url, $file ) |
mirror( $url, $file ) |
16 |
== RC_NOT_MODIFIED |
== RC_NOT_MODIFIED |
17 |
&& warn(" not modified\n") |
&& warn(" not modified\n") |
59 |
|
|
60 |
sub files { |
sub files { |
61 |
my $url = shift; |
my $url = shift; |
62 |
|
my @files = @_; |
63 |
|
|
64 |
|
if ( ! @files ) { |
65 |
|
push @files, $1 if $url =~ s{/([^/]+)$}{}; |
66 |
|
} |
67 |
|
|
68 |
my $name = (caller(1))[3]; |
my $name = (caller(1))[3]; |
69 |
$name =~ s{config::}{} || die "caller isn't package config !"; |
$name =~ s{config::}{} || die "caller isn't package config !"; |
70 |
|
|
71 |
my $path = "$server::base_dir/tftp/$name"; |
my $path = "$server::base_dir/tftp/$name"; |
72 |
|
mkdir $path unless -d $path; |
73 |
|
|
74 |
foreach my $file ( @_ ) { |
warn "# files $url ",dump( @files ), " -> $path\n"; |
|
mirror_file "$url/$file", "$path/$file" |
|
|
if first_time( "$url/$file" ); |
|
|
} |
|
|
} |
|
|
|
|
|
sub mkpath { |
|
|
my $file = shift; |
|
75 |
|
|
76 |
my @file_parts = split m{/}, $file; |
foreach my $file ( @files ) { |
77 |
foreach ( 1 .. $#file_parts - 1 ) { |
mirror_file( "$url/$file", "$path/$file" ) |
78 |
my $path = splice @file_parts, 0, $_; |
if ! -e "$path/$file" || first_time( "$url/$file" ); |
|
warn "? $path\n"; |
|
|
mkdir $path unless -e $path; |
|
79 |
} |
} |
80 |
} |
} |
81 |
|
|