aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Youri/Upload/Check/Version.pm
blob: fe9f42b8bee33756646bb124f9dfb4a71918589f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# $Id: /youri.mdv/trunk/lib/Youri/Upload/Check/Recency.pm 975 2006-08-05T08:30:57.188281Z warly  $
package Youri::Upload::Check::Version;

=head1 NAME

Youri::Upload::Check::Version - Check if older version already exist in cooker (used in freeze period)

=head1 DESCRIPTION

This check plugin rejects new version of packages if they are not mentioned as authorized 
in the configuration file or in a non frozen section.

=cut

use warnings;
use strict;
use Carp;
use URPM;
use base qw/Youri::Upload::Check/;

sub _init {
    my $self   = shift;
    my %options = (
        @_
    );

    foreach my $target (keys %options) { 
	$self->{$target} = $options{$target}
    }
}

sub run {
    my ($self, $package, $repository, $target, $define) = @_;
    croak "Not a class method" unless ref $self;
    my $opt = $self->{$target};
    return 1 if $opt->{mode} eq 'normal';
    my $section = $repository->_get_section($package, $target, $define);
    my $name = $package->get_canonical_name;
    return 1 if $name =~ /$opt->{authorized_packages}/;
    my $arch = $repository->get_arch($package, $target, $define);
    return 1 if $arch =~ /$opt->{authorized_arches}/;
    if ($opt->{mode} eq 'version_freeze') {
	return 1 if $section =~ /$opt->{authorized_sections}/
    } elsif ($opt->{mode} eq 'freeze') {
	if ($section !~ /$opt->{authorized_sections}/) {
	     $self->{_error} = "FREEZE: repository $target section $section is frozen, you can still submit your packages in testing\nTo do so use your.devel --define section=<section> $target <package 1> <package 2> ... <package n>";
	     return 0
	 }
    }
    my $source = $package->get_source_package;
    my ($package_version) = $source =~ /-([^-]+)-[^-]+\.src\.rpm$/;
    $define->{arch} = 'src';
    my @revisions = $repository->get_revisions($package, $target, $define, sub { my $source_package = $_[0]->get_source_package; my ($version) = $source_package =~ /-([^-]+)-[^-]+\.src\.rpm$/; print STDERR "Found version $version\n"; URPM::ranges_overlap("== $version", "< $package_version") });
    $define->{arch} = '';
    if (@revisions) {
	$self->{_error} = "VERSION FREEZE, package @revisions of different versions exist in cooker\n";
	return 0
    }
    return 1
}

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2006, YOURI project
Copyright (C) 2006, Mandriva

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

=cut

1;