/[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 532 by dpavlin, Fri Sep 17 19:35:50 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 unless once::first_time $file;
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    
25  my $once_path = '/tmp/pxelator.once';  =head2 iso
26  our $just_once = retrieve $once_path if -e $once_path;  
27  sub first_time {    my $iso_path = upstream::iso 'http://example.com/bootable.iso';
28          my $what = shift;  
29          return if $just_once->{$what}++;  =cut
         store $just_once, $once_path;  
         return 1;  
 }  
30    
31  sub iso {  sub iso {
32          my $url = shift;          my $url = shift;
33    
         return if ! first_time($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 41  sub iso { Line 39  sub iso {
39          my $dir = "$server::base_dir/iso";          my $dir = "$server::base_dir/iso";
40          mkdir $dir unless -e $dir;          mkdir $dir unless -e $dir;
41    
42          my $file = $1 if $url =~ m{/([^/]+\.iso$)}i;          my $file = $1 if $url =~ m{/([^/]+\.iso)}i;
43          die "can't find iso file in $url" unless $file;          die "can't find iso file in $url" unless $file;
44    
45          my $iso = "$dir/$file";          my $iso = "$dir/$file";
# Line 55  sub iso { Line 53  sub iso {
53          mkdir $mnt unless -d $mnt;          mkdir $mnt unless -d $mnt;
54    
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            return $iso;
57  }  }
58    
59    =head2 files
60    
61      my $to_dir = upstream::files qw(http://base.url.example.com/ file1 file2 file2);
62    
63    =cut
64    
65  sub files {  sub files {
66          my $url = shift;          my $url = shift;
67          my @files = @_;          my @files = @_;
# Line 75  sub files { Line 80  sub files {
80    
81          foreach my $file ( @files ) {          foreach my $file ( @files ) {
82                  mirror_file( "$url/$file", "$path/$file" )                  mirror_file( "$url/$file", "$path/$file" )
83                          if ! -e "$path/$file" || first_time( "$url/$file" );                          if ! -e "$path/$file" || once::first_time( "$url/$file" );
84          }          }
 }  
   
 sub mkpath {  
         my $file = shift;  
85    
86          my @file_parts = split m{/}, $file;          return $path;
         foreach ( 1 .. $#file_parts - 1 ) {  
                 my $path = splice @file_parts, 0, $_;  
                 warn "? $path\n";  
                 mkdir $path unless -e $path;  
         }  
87  }  }
88    
89  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26