--- lib/PXElator/upstream.pm 2009/08/17 10:28:17 242 +++ lib/PXElator/upstream.pm 2010/05/03 15:15:08 500 @@ -4,13 +4,14 @@ use strict; use autodie; +use Data::Dump qw/dump/; use LWP::Simple qw/mirror RC_NOT_MODIFIED/; -use Storable; 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") @@ -18,20 +19,9 @@ ; } -my $once_path = '/tmp/pxelator.once'; -our $just_once = retrieve $once_path if -e $once_path; -sub first_time { - my $what = shift; - return if $just_once->{$what}++; - store $just_once, $once_path; - return 1; -} - sub iso { my $url = shift; - return if ! first_time($url); - my $name = (caller(1))[3]; $name =~ s{config::}{} || die "caller isn't package config !"; @@ -40,12 +30,12 @@ my $dir = "$server::base_dir/iso"; mkdir $dir unless -e $dir; - my $file = $1 if $url =~ m{/([^/]+\.iso$)}i; + my $file = $1 if $url =~ m{/([^/]+\.iso)}i; die "can't find iso file in $url" unless $file; 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"; @@ -58,26 +48,23 @@ 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; - foreach my $file ( @_ ) { - mirror_file "$url/$file", "$path/$file" - if first_time( "$url/$file" ); - } -} - -sub mkpath { - my $file = shift; + warn "# files $url ",dump( @files ), " -> $path\n"; - 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; + foreach my $file ( @files ) { + mirror_file( "$url/$file", "$path/$file" ) + if ! -e "$path/$file" || once::first_time( "$url/$file" ); } }