--- /dev/null
+package once;
+
+use Storable;
+
+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;
+}
+
+1;
--- /dev/null
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use autodie;
+
+use Test::More tests => 4;
+
+use_ok 'once';
+
+ok( my $rand = rand(), 'rand' );
+ok( once::first_time("test-$rand"), 'first_time' );
+ok( ! once::first_time("test-$rand"), 'first_time again' );
+
use Data::Dump qw/dump/;
use LWP::Simple qw/mirror RC_NOT_MODIFIED/;
-use Storable;
use server;
+use once;
sub mirror_file {
my ( $url, $file ) = @_;
;
}
-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;
-}
-
sub iso {
my $url = shift;
my $iso = "$dir/$file";
- mirror_file( $url, $iso ) if first_time $url;
+ mirror_file( $url, $iso ) if once::first_time $url;
$file =~ s{\.iso$}{}i;
my $mnt = "$server::base_dir/tftp/$name";
foreach my $file ( @files ) {
mirror_file( "$url/$file", "$path/$file" )
- if ! -e "$path/$file" || first_time( "$url/$file" );
+ if ! -e "$path/$file" || once::first_time( "$url/$file" );
}
}