/[pxelator]/lib/PXElator/upstream.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/upstream.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 242 by dpavlin, Mon Aug 17 10:28:17 2009 UTC revision 276 by dpavlin, Thu Aug 20 17:36:17 2009 UTC
# Line 4  use warnings; Line 4  use warnings;
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/;
 use Storable;  
9  use server;  use server;
10    use once;
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")
# Line 18  sub mirror_file { Line 19  sub mirror_file {
19                  ;                  ;
20  }  }
21    
 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;  
 }  
   
22  sub iso {  sub iso {
23          my $url = shift;          my $url = shift;
24    
         return if ! first_time($url);  
   
25          my $name = (caller(1))[3];          my $name = (caller(1))[3];
26          $name =~ s{config::}{} || die "caller isn't package config !";          $name =~ s{config::}{} || die "caller isn't package config !";
27    
# Line 45  sub iso { Line 35  sub iso {
35    
36          my $iso = "$dir/$file";          my $iso = "$dir/$file";
37    
38          mirror_file( $url, $iso );          mirror_file( $url, $iso ) if once::first_time $url;
39    
40          $file =~ s{\.iso$}{}i;          $file =~ s{\.iso$}{}i;
41          my $mnt = "$server::base_dir/tftp/$name";          my $mnt = "$server::base_dir/tftp/$name";
# Line 58  sub iso { Line 48  sub iso {
48    
49  sub files {  sub files {
50          my $url = shift;          my $url = shift;
51            my @files = @_;
52    
53            if ( ! @files ) {
54                    push @files, $1 if $url =~ s{/([^/]+)$}{};
55            }
56    
57          my $name = (caller(1))[3];          my $name = (caller(1))[3];
58          $name =~ s{config::}{} || die "caller isn't package config !";          $name =~ s{config::}{} || die "caller isn't package config !";
59    
60          my $path = "$server::base_dir/tftp/$name";          my $path = "$server::base_dir/tftp/$name";
61            mkdir $path unless -d $path;
62    
63          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;  
64    
65          my @file_parts = split m{/}, $file;          foreach my $file ( @files ) {
66          foreach ( 1 .. $#file_parts - 1 ) {                  mirror_file( "$url/$file", "$path/$file" )
67                  my $path = splice @file_parts, 0, $_;                          if ! -e "$path/$file" || once::first_time( "$url/$file" );
                 warn "? $path\n";  
                 mkdir $path unless -e $path;  
68          }          }
69  }  }
70    

Legend:
Removed from v.242  
changed lines
  Added in v.276

  ViewVC Help
Powered by ViewVC 1.1.26