--- lib/PXElator/upstream.pm 2009/08/04 15:25:09 138 +++ lib/PXElator/upstream.pm 2009/08/05 13:08:28 147 @@ -7,6 +7,16 @@ use LWP::Simple qw/mirror RC_NOT_MODIFIED/; use server; +sub mirror_file { + my ( $url, $file ) = @_; + print STDERR "mirror $url"; + mirror( $url, $file ) + == RC_NOT_MODIFIED + && warn(" not modified\n") + || warn(" done ", -s $file, " bytes\n") + ; +} + our $just_once; sub iso { @@ -27,12 +37,7 @@ my $iso = "$dir/$file"; - print STDERR "$name mirror $url"; - mirror( $url, $iso ) - == RC_NOT_MODIFIED - && warn(" not modified\n") - || warn(" done ", -s $iso, " bytes\n") - ; + mirror_file( $url, $iso ); $file =~ s{\.iso$}{}i; my $mnt = "$server::base_dir/tftp/$name"; @@ -40,7 +45,19 @@ $mnt .= '/iso'; mkdir $mnt unless -d $mnt; - system("mount -t iso9660 | grep $mnt || sudo mount $iso $mnt -o loop -t iso9660 -v") == 0; + 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; + } + mirror_file( $url, "$server::base_dir/$file" ); } 1;