lib/Debian/Repository.pm
changeset 1 05c025e89571
equal deleted inserted replaced
0:0d30ea853889 1:05c025e89571
       
     1 package Debian::Repository;
       
     2 
       
     3 use strict;
       
     4 use warnings;
       
     5 
       
     6 use File::Path;
       
     7 
       
     8 sub new {
       
     9     my $class = ref $_[0] ? ref shift : shift;
       
    10     my $self = bless {}, $class;
       
    11 
       
    12     $self->{vars} = shift;
       
    13 
       
    14     return $self;
       
    15 }
       
    16 
       
    17 sub origin { $_[0]->{vars}{origin} }
       
    18 sub dists { $_[0]->{vars}{dists} }
       
    19 sub sections { $_[0]->{vars}{sections} }
       
    20 sub binary { $_[0]->{vars}{binary} }
       
    21 sub source { $_[0]->{vars}{source} }
       
    22 sub root { $_[0]->{vars}{root} }
       
    23 
       
    24 sub checkDirs {
       
    25     my $self = shift;
       
    26 
       
    27     my %args = @_;
       
    28 
       
    29     $args{create} ||= 0;
       
    30     $args{umask} ||= umask;
       
    31 
       
    32     my $root = $self->root;
       
    33     my $dists = $self->dists;
       
    34     my $sections = $self->sections;
       
    35     my $binary = $self->binary;
       
    36     my $source =$self->source;
       
    37     my $origin = $self->origin;
       
    38 
       
    39     my (@dirs, @archdirs);
       
    40     push @dirs, "$root/pool";
       
    41     foreach my $dir (map { "$root/dists/$_" } @$dists) {
       
    42 	push @dirs, $dir;
       
    43 	foreach my $section (@$sections) {
       
    44 	    push @dirs, "$dir/$section";
       
    45 	    foreach my $arch (@$binary) {
       
    46 		push @dirs, "$dir/$section/binary-$arch";
       
    47 		push @archdirs, { dir => $dirs[-1], arch => $arch };
       
    48 	    }
       
    49 	    foreach my $arch (@$source) {
       
    50 		push @dirs, "$dir/$section/$arch";
       
    51 		push @archdirs, { dir => $dirs[-1], arch => $arch };
       
    52 	    }
       
    53 	}
       
    54     }
       
    55 
       
    56     # create dirs
       
    57     if ($args{create}) {
       
    58 	my $mask = umask($args{umask});
       
    59 	foreach (@dirs) {
       
    60 	    -d $_ or mkdir($_) or die "Can't mkdir $_: $!\n";
       
    61 	}
       
    62 
       
    63 	# create relases files
       
    64 	foreach my $dist (@$dists) {
       
    65 	    #foreach my $dir ("$root/dists/$dist", @archdirs) {
       
    66 	    foreach my $d (@archdirs) {
       
    67 		my ($dir, $arch);
       
    68 		if (ref $d eq "HASH") {
       
    69 		    $arch = $d->{arch};
       
    70 		    $dir = $d->{dir};
       
    71 		} else { $dir = $d }
       
    72 
       
    73 		$_ = "$dir/Release";
       
    74 		my $r = new IO::File ">$_" or die "Can't open >$_: $!\n";
       
    75 		$r->print(<<___);
       
    76 Release: $dist
       
    77 Suite: $dist
       
    78 Origin: $origin
       
    79 ___
       
    80 		$r->print("Architecture: $arch\n") if defined $arch;
       
    81 	    }
       
    82 	}
       
    83 	umask($mask);
       
    84     }
       
    85 }
       
    86 
       
    87 1;
       
    88 
       
    89 # vim:sts=4 sw=4 aw ai sm: