/[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 147 by dpavlin, Wed Aug 5 13:08:28 2009 UTC revision 272 by dpavlin, Wed Aug 19 23:12:02 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/;
9    use Storable;
10  use server;  use server;
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 17  sub mirror_file { Line 19  sub mirror_file {
19                  ;                  ;
20  }  }
21    
22  our $just_once;  my $once_path = '/tmp/pxelator.once';
23    our $just_once = retrieve $once_path if -e $once_path;
24    sub first_time {
25            my $what = shift;
26            return if $just_once->{$what}++;
27            store $just_once, $once_path;
28            return 1;
29    }
30    
31  sub iso {  sub iso {
32          my $url = shift;          my $url = shift;
33    
         return if $just_once->{$url}++;  
   
34          my $name = (caller(1))[3];          my $name = (caller(1))[3];
35          $name =~ s{config::}{} || die "caller isn't package config !";          $name =~ s{config::}{} || die "caller isn't package config !";
36    
# Line 37  sub iso { Line 44  sub iso {
44    
45          my $iso = "$dir/$file";          my $iso = "$dir/$file";
46    
47          mirror_file( $url, $iso );          mirror_file( $url, $iso ) if first_time $url;
48    
49          $file =~ s{\.iso$}{}i;          $file =~ s{\.iso$}{}i;
50          my $mnt = "$server::base_dir/tftp/$name";          my $mnt = "$server::base_dir/tftp/$name";
# Line 48  sub iso { Line 55  sub iso {
55          system("mount -t iso9660 | grep $name/iso || 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;
56  }  }
57    
58  sub file {  sub files {
59          my ( $url, $file ) = @_;          my $url = shift;
60          my $path = "$server::base_dir/$file";          my @files = @_;
61          my @file_parts = split m{/}, $file;  
62          foreach ( 1 .. $#file_parts - 1 ) {          if ( ! @files ) {
63                  my $path = splice @file_parts, 0, $_;                  push @files, $1 if $url =~ s{/([^/]+)$}{};
64                  warn "? $path\n";          }
65                  mkdir $path unless -e $path;  
66            my $name = (caller(1))[3];
67            $name =~ s{config::}{} || die "caller isn't package config !";
68    
69            my $path = "$server::base_dir/tftp/$name";
70            mkdir $path unless -d $path;
71    
72            warn "# files $url ",dump( @files ), " -> $path\n";
73    
74            foreach my $file ( @files ) {
75                    mirror_file( "$url/$file", "$path/$file" )
76                            if ! -e "$path/$file" || first_time( "$url/$file" );
77          }          }
         mirror_file( $url, "$server::base_dir/$file" );  
78  }  }
79    
80  1;  1;

Legend:
Removed from v.147  
changed lines
  Added in v.272

  ViewVC Help
Powered by ViewVC 1.1.26