/[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 266 by dpavlin, Wed Aug 19 17:00:46 2009 UTC revision 508 by dpavlin, Wed Jul 21 16:17:46 2010 UTC
# Line 6  use autodie; Line 6  use autodie;
6    
7  use Data::Dump qw/dump/;  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    
15            return if ! once::first_time $url;
16    
17          warn "mirror_file $url -> $file\n";          warn "mirror_file $url -> $file\n";
18          mirror( $url, $file )          mirror( $url, $file )
19                  == RC_NOT_MODIFIED                  == RC_NOT_MODIFIED
# Line 19  sub mirror_file { Line 22  sub mirror_file {
22                  ;                  ;
23  }  }
24    
 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;  
 }  
   
25  sub iso {  sub iso {
26          my $url = shift;          my $url = shift;
27    
         return if ! first_time($url);  
   
28          my $name = (caller(1))[3];          my $name = (caller(1))[3];
29          $name =~ s{config::}{} || die "caller isn't package config !";          $name =~ s{config::}{} || die "caller isn't package config !";
30    
# Line 41  sub iso { Line 33  sub iso {
33          my $dir = "$server::base_dir/iso";          my $dir = "$server::base_dir/iso";
34          mkdir $dir unless -e $dir;          mkdir $dir unless -e $dir;
35    
36          my $file = $1 if $url =~ m{/([^/]+\.iso$)}i;          my $file = $1 if $url =~ m{/([^/]+\.iso)}i;
37          die "can't find iso file in $url" unless $file;          die "can't find iso file in $url" unless $file;
38    
39          my $iso = "$dir/$file";          my $iso = "$dir/$file";
# Line 75  sub files { Line 67  sub files {
67    
68          foreach my $file ( @files ) {          foreach my $file ( @files ) {
69                  mirror_file( "$url/$file", "$path/$file" )                  mirror_file( "$url/$file", "$path/$file" )
70                          if ! -e "$path/$file" || first_time( "$url/$file" );                          if ! -e "$path/$file" || once::first_time( "$url/$file" );
         }  
 }  
   
 sub mkpath {  
         my $file = shift;  
   
         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;  
71          }          }
72  }  }
73    

Legend:
Removed from v.266  
changed lines
  Added in v.508

  ViewVC Help
Powered by ViewVC 1.1.26