This file is indexed.

/usr/share/perl5/Munin/Node/Configure/History.pm is in munin-node 2.0.19-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package Munin::Node::Configure::History;

# $Id$

use strict;
use warnings;

use base 'Munin::Common::Config';

use POSIX ();
use Munin::Node::Configure::Debug;


sub new
{
    my ($class, %opts) = @_;

    my $newer        = delete $opts{newer};
    my $history_file = delete $opts{history_file} or die "A history file must be specified\n";

    my %history = (
        newer        => $newer,
        history_file => $history_file,
    );

    return bless \%history, $class;
}


sub load
{
    my ($self) = @_;

    my $reached_version = 0;
    my $ver = "0.0.0";

    return unless $self->{newer};

    DEBUG("Loading plugin history from '$self->{history_file}'");

    open(my $HIST, '<', $self->{history_file})
        or die "# ERROR: Could not open '$self->{history_file}': $!\n";

    # $^O or $Config{osname} are based on the platform perl was built on,
    # not where it's currently running.  This should always be correct
    my $uname = lc((POSIX::uname)[0]);

    while (my $line = <$HIST>) {
        $self->_strip_comment($line);
        $self->_trim($line);
        next unless length $line;

        if ($line =~ /^ \[ ([^\]]+) \] $/x) {
            $ver = $1;
            DEBUG("Setting version to '$ver'.");
            if ($ver eq $self->{newer}) {
                $reached_version = 1;
            } elsif ($reached_version) {
                $reached_version++;
            }
        }
        elsif ($reached_version < 2) {
            next;
        }
        elsif ($line =~ m{^ ([^/]+) / (.+) }x) {
            if ($uname eq $1) {
                $self->{valid_plugins}{$2} = 1;
                DEBUG("\tAdding plugin '$2' to version tree.");
            }
            else {
                DEBUG("\tPlugin '$2' applies to another architecture ($1).");
            }
        }
        else {
            $self->{valid_plugins}{$line} = 1;
            DEBUG("\tAdding plugin '$line' to version tree.");
        }
    }
    close $HIST;

    # FIXME: still not a good error message.  should this be non-fatal?
    die "# FATAL: version '$self->{newer}' was not found in the plugin history file\n"
        unless ($reached_version);

    return;
}


sub too_old
{
    my ($self, $plugin) = @_;

    return 0 unless $self->{newer};
    return 0 unless $plugin->in_family('auto');
    return 0 if $self->{valid_plugins}{$plugin->{name}};
    return 1;
}


1;

__END__

=head1 NAME

Munin::Node::Configure::History - Filtering plugins based on the version of
Munin they were first distributed with.


=head1 SYNOPSIS

  my $plugin = Munin::Node::Configure::History->new(
      newer        => '1.3.3',
      history_file => 'plugins/plugins.history',
  );


=head1 METHODS

=over

=item B<new(%args)>

Constructor.

The 'history_file' argument is required, and should be the path to the plugin
history file.  The 'newer' argument is optional, and should be the version of
the release before which plugins should be ignored.


=item B<load()>

Loads the plugin history from history_file.  Dies if 'newer' didn't match a
valid release, or the file wasn't readable.


=item B<too_old($plugin)>

Takes a Munin::Node::Configure::Plugin object.  Returns false unless the
plugin should be ignored, true otherwise (ie. if 'newer' wasn't set, the plugin
is user-contributed, etc).

=cut
# vim: sw=4 : ts=4 : expandtab