This file is indexed.

/usr/share/perl5/Prophet/Conflict.pm is in libprophet-perl 0.750-1.

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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package Prophet::Conflict;
use Any::Moose;
use Params::Validate;
use Prophet::ConflictingPropChange;
use Prophet::ConflictingChange;

has prophet_handle => (
    is  => 'rw',
    isa => 'Prophet::Replica',
);

has resolvers => (
    is         => 'rw',
    isa        => 'ArrayRef',
    default    => sub { [] },
    auto_deref => 1,
);

has changeset => (
    is  => 'rw',
    isa => 'Prophet::ChangeSet',
);

has nullification_changeset => (
    is  => 'rw',
    isa => 'Prophet::ChangeSet',
);

has resolution_changeset => (
    is  => 'rw',
    isa => 'Prophet::ChangeSet',
);

has autoresolved => (
    is  => 'rw',
    isa => 'Bool',
);

has conflicting_changes => (
    is        => 'ro',
    isa       => 'ArrayRef',
    default   => sub { [] },
);

sub has_conflicting_changes { scalar @{ $_[0]->conflicting_changes } }
sub add_conflicting_change  {
    my $self = shift;
    push @{ $self->conflicting_changes }, @_;
}

=head2 analyze_changeset Prophet::ChangeSet

Take a look at a changeset. if there are any conflicts, populate
the L<conflicting_changes> array on this object with a set of
L<Prophet::ConflictingChange> objects.

=cut

sub analyze_changeset {
    my $self = shift;

    #my ($changeset) = validate_pos( @_, { isa => 'Prophet::ChangeSet' } );

    $self->generate_changeset_conflicts();
    return unless $self->has_conflicting_changes;

    $self->generate_nullification_changeset;

    return 1;
}

use Prophet::Resolver::IdenticalChanges;
use Prophet::Resolver::FromResolutionDB;
use Prophet::Resolver::Fixup::MissingSourceOldValues;
use Prophet::Resolver::Failed;
use Prophet::Resolver::Prompt;

sub generate_resolution {
    my $self      = shift;
    my $resdb     = shift;
    my @resolvers = (
        sub { Prophet::Resolver::IdenticalChanges->new->run(@_); },
        $resdb ? sub { Prophet::Resolver::FromResolutionDB->new->run(@_) } : (),
        $self->resolvers,
        sub { Prophet::Resolver::Fixup::MissingSourceOldValues->new->run(@_)},
        (-t STDIN && -t STDOUT) ? sub { Prophet::Resolver::Prompt->new->run(@_) } : (),
        sub { Prophet::Resolver::Failed->new->run(@_) },
    );
    my $resolutions = Prophet::ChangeSet->new({
        creator       => $self->prophet_handle->changeset_creator,
        is_resolution => 1,
    });
    for my $conflicting_change ( @{ $self->conflicting_changes } ) {
        for (@resolvers) {
            if ( my $resolution = $_->( $conflicting_change, $self, $resdb ) ) {
                $resolutions->add_change( change => $resolution ) if $resolution->has_prop_changes;
                last;
            }
        }
    }

    $self->resolution_changeset($resolutions);
    return 1;
}

=head2 generate_changeset_conflicts 

Given a changeset, populates $self->conflicting_changes with all the conflicts that applying that changeset to the target replica would result in.

=cut

sub generate_changeset_conflicts {
    my $self = shift;
    for my $change ( $self->changeset->changes ) {
        if ( my $change_conflicts = $self->_generate_change_conflicts($change) ) {
            $self->add_conflicting_change($change_conflicts);
        }
    }
}

=head2 _generate_change_conflicts Prophet::Change

Given a change, generates a set of Prophet::ConflictingChange entries.

=cut

sub _generate_change_conflicts {
    my $self = shift;
    my ($change) = validate_pos( @_, { isa => "Prophet::Change" } );
    my $file_op_conflict;

    my $file_exists = $self->prophet_handle->record_exists(
        uuid => $change->record_uuid,
        type => $change->record_type
    );

    # It's ok to delete a record that exists
    if ( $change->change_type eq 'delete' && !$file_exists ) {
        $file_op_conflict = "delete_missing_file";
    }
    elsif ( $change->change_type eq 'update_file' && !$file_exists ) {
        $file_op_conflict = "update_missing_file";
    }
    elsif ( $change->change_type eq 'add_file' && $file_exists ) {
        # we can recover from "Trying to add a file which exists" by converting it to an "update file"
        # operation. This should ONLY ever happen on settings conflicts
        $change->change_type('update_file');

    }
    elsif ( $change->change_type eq 'add_dir' && $file_exists ) {

        # XXX TODO: this isn't right
        $file_op_conflict = "create_existing_dir";
    }

    my $change_conflict = Prophet::ConflictingChange->new(
        {
            record_type          => $change->record_type,
            record_uuid          => $change->record_uuid,
            target_record_exists => ($file_exists ? 1 : 0 ),
            change_type          => $change->change_type,
            $file_op_conflict ? ( file_op_conflict => $file_op_conflict ) : (),
        }
    );

    if ($file_exists) {
        my $current_state = $self->prophet_handle->get_record_props(
            uuid => $change->record_uuid,
            type => $change->record_type
        );

        $change_conflict->add_prop_conflict(
            $self->_generate_prop_change_conflicts( $change, $current_state ) );
    }

    return ( $change_conflict->has_prop_conflicts || $file_op_conflict )
      ? $change_conflict
      : undef;
}

=head2 _generate_prop_change_conflicts Prophet::Change %hash_of_current_properties

Given a change and the current state of a record, returns an array of Prophet::ConflictingPropChange objects describing conflicts which would occur if the change were applied


=cut

sub _generate_prop_change_conflicts {
    my $self          = shift;
    my $change        = shift;
    my $current_state = shift;
    my @prop_conflicts;
    for my $prop_change ( $change->prop_changes ) {

        # skip properties added by the change
        next if ( !defined $current_state->{ $prop_change->name } && !defined $prop_change->old_value );

       # If either the old version didn't have a value or the delta didn't have a value, then we know there's a conflict
        my $s = {
            name             => $prop_change->name,
            source_old_value => $prop_change->old_value,
            target_value     => $current_state->{ $prop_change->name },
            source_new_value => $prop_change->new_value
        };

        my $old_exists =
          ( defined $prop_change->old_value && $prop_change->old_value ne '' )
          ? 1
          : 0;
        my $current_exists =
          exists $current_state->{ $prop_change->name }
          ? 1
          : 0;

        no warnings 'uninitialized';
        if ( 
               (  $current_exists != $old_exists)
            || ( $current_state->{ $prop_change->name } ne $prop_change->old_value ) )
        {
            push @prop_conflicts, Prophet::ConflictingPropChange->new($s);
        }

    }
    return @prop_conflicts;
}

=head2 generate_nullification_changeset

In order to record a changeset which might not apply cleanly to the
current state of a replica, Prophet generates a I<nullification
changeset>. That is, a changeset which sets the state of the replica
back to what it needs to be in order to apply the new changeset.

This routine computes a new L<Prophet::ChangeSet> which contains
everything needed to nullify the conflicting state of the replica.

=cut

sub generate_nullification_changeset {
    my $self = shift;
    my $nullification = Prophet::ChangeSet->new({
        is_nullification => 1,
        creator => undef,
        created => undef,
    });

    for my $conflict ( @{ $self->conflicting_changes } ) {
        my $nullify_conflict
            = Prophet::Change->new( { record_type => $conflict->record_type, record_uuid => $conflict->record_uuid } );

        my $file_op_conflict = $conflict->file_op_conflict || '';
        if ( $file_op_conflict eq "delete_missing_file" ) {
            $nullify_conflict->change_type('add_file');
        } elsif ( $file_op_conflict eq "update_missing_file" ) {
            $nullify_conflict->change_type('add_file');
        } elsif ( $file_op_conflict eq "create_existing_file" ) {
            $nullify_conflict->change_type('delete');
        } elsif ( $file_op_conflict ) {
            die "We don't know how to deal with a conflict of type " . $conflict->file_op_conflict;
        } else {
            $nullify_conflict->change_type('update_file');
        }

        # now that we've sorted out all the file-level conflicts, we need to get properties in order
        for my $prop_conflict ( @{ $conflict->prop_conflicts } ) {
            $nullify_conflict->add_prop_change(
                name => $prop_conflict->name,
                old  => $prop_conflict->target_value,
                new  => $prop_conflict->source_old_value
            );
        }
        $nullification->add_change( change => $nullify_conflict );
    }

    $self->nullification_changeset($nullification);
}

__PACKAGE__->meta->make_immutable;
no Any::Moose;

1;