--- lib/PXElator/upstream.pm 2009/08/05 13:08:28 147 +++ lib/PXElator/upstream.pm 2009/08/20 17:36:17 276 @@ -4,12 +4,14 @@ use strict; use autodie; +use Data::Dump qw/dump/; use LWP::Simple qw/mirror RC_NOT_MODIFIED/; use server; +use once; sub mirror_file { my ( $url, $file ) = @_; - print STDERR "mirror $url"; + warn "mirror_file $url -> $file\n"; mirror( $url, $file ) == RC_NOT_MODIFIED && warn(" not modified\n") @@ -17,13 +19,9 @@ ; } -our $just_once; - sub iso { my $url = shift; - return if $just_once->{$url}++; - my $name = (caller(1))[3]; $name =~ s{config::}{} || die "caller isn't package config !"; @@ -37,7 +35,7 @@ my $iso = "$dir/$file"; - mirror_file( $url, $iso ); + mirror_file( $url, $iso ) if once::first_time $url; $file =~ s{\.iso$}{}i; my $mnt = "$server::base_dir/tftp/$name"; @@ -48,16 +46,26 @@ system("mount -t iso9660 | grep $name/iso || sudo mount $iso $mnt -o loop -t iso9660 -v") == 0; } -sub file { - my ( $url, $file ) = @_; - my $path = "$server::base_dir/$file"; - my @file_parts = split m{/}, $file; - foreach ( 1 .. $#file_parts - 1 ) { - my $path = splice @file_parts, 0, $_; - warn "? $path\n"; - mkdir $path unless -e $path; +sub files { + my $url = shift; + my @files = @_; + + if ( ! @files ) { + push @files, $1 if $url =~ s{/([^/]+)$}{}; + } + + my $name = (caller(1))[3]; + $name =~ s{config::}{} || die "caller isn't package config !"; + + my $path = "$server::base_dir/tftp/$name"; + mkdir $path unless -d $path; + + warn "# files $url ",dump( @files ), " -> $path\n"; + + foreach my $file ( @files ) { + mirror_file( "$url/$file", "$path/$file" ) + if ! -e "$path/$file" || once::first_time( "$url/$file" ); } - mirror_file( $url, "$server::base_dir/$file" ); } 1;