This file is indexed.

/usr/share/perl5/DBM/Deep/Engine/DBI.pm is in libdbm-deep-perl 2.0002-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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
package DBM::Deep::Engine::DBI;

use 5.008_004;

use strict;
use warnings FATAL => 'all';
no warnings 'recursion';

use base 'DBM::Deep::Engine';

use DBM::Deep::Sector::DBI ();
use DBM::Deep::Storage::DBI ();

sub sector_type { 'DBM::Deep::Sector::DBI' }
sub iterator_class { 'DBM::Deep::Iterator::DBI' }

sub new {
    my $class = shift;
    my ($args) = @_;

    $args->{storage} = DBM::Deep::Storage::DBI->new( $args )
        unless exists $args->{storage};

    my $self = bless {
        storage => undef,
        external_refs => undef,
    }, $class;

    # Grab the parameters we want to use
    foreach my $param ( keys %$self ) {
        next unless exists $args->{$param};
        $self->{$param} = $args->{$param};
    }

    return $self;
}

sub setup {
    my $self = shift;
    my ($obj) = @_;

    # Default the id to 1. This means that we will be creating a row if there
    # isn't one. The assumption is that the row_id=1 cannot never be deleted. I
    # don't know if this is a good assumption.
    $obj->{base_offset} ||= 1;

    my ($rows) = $self->storage->read_from(
        refs => $obj->_base_offset,
        qw( ref_type ),
    );

    # We don't have a row yet.
    unless ( @$rows ) {
        $self->storage->write_to(
            refs => $obj->_base_offset,
            ref_type => $obj->_type,
        );
    }

    my $sector = DBM::Deep::Sector::DBI::Reference->new({
        engine => $self,
        offset => $obj->_base_offset,
    });
}

sub read_value {
    my $self = shift;
    my ($obj, $key) = @_;

    my $sector = $self->load_sector( $obj->_base_offset, 'refs' )
        or return;

#    if ( $sector->staleness != $obj->_staleness ) {
#        return;
#    }

#    my $key_md5 = $self->_apply_digest( $key );

    my $value_sector = $sector->get_data_for({
        key => $key,
#        key_md5    => $key_md5,
        allow_head => 1,
    });

    unless ( $value_sector ) {
        return undef
    }

    return $value_sector->data;
}

sub get_classname {
    my $self = shift;
    my ($obj) = @_;

    my $sector = $self->load_sector( $obj->_base_offset, 'refs' )
        or return;

    return $sector->get_classname;
}

sub make_reference {
    my $self = shift;
    my ($obj, $old_key, $new_key) = @_;

    my $sector = $self->load_sector( $obj->_base_offset, 'refs' )
        or return;

#    if ( $sector->staleness != $obj->_staleness ) {
#        return;
#    }

    my $value_sector = $sector->get_data_for({
        key        => $old_key,
        allow_head => 1,
    });

    unless ( $value_sector ) {
        $value_sector = DBM::Deep::Sector::DBI::Scalar->new({
            engine => $self,
            data   => undef,
        });

        $sector->write_data({
            key     => $old_key,
            value   => $value_sector,
        });
    }

    if ( $value_sector->isa( 'DBM::Deep::Sector::DBI::Reference' ) ) {
        $sector->write_data({
            key     => $new_key,
            value   => $value_sector,
        });
        $value_sector->increment_refcount;
    }
    else {
        $sector->write_data({
            key     => $new_key,
            value   => $value_sector->clone,
        });
    }

    return;
}

# exists returns '', not undefined.
sub key_exists {
    my $self = shift;
    my ($obj, $key) = @_;

    my $sector = $self->load_sector( $obj->_base_offset, 'refs' )
        or return '';

#    if ( $sector->staleness != $obj->_staleness ) {
#        return '';
#    }

    my $data = $sector->get_data_for({
#        key_md5    => $self->_apply_digest( $key ),
        key        => $key,
        allow_head => 1,
    });

    # exists() returns 1 or '' for true/false.
    return $data ? 1 : '';
}

sub delete_key {
    my $self = shift;
    my ($obj, $key) = @_;

    my $sector = $self->load_sector( $obj->_base_offset, 'refs' )
        or return '';

#    if ( $sector->staleness != $obj->_staleness ) {
#        return '';
#    }

    return $sector->delete_key({
#        key_md5    => $self->_apply_digest( $key ),
        key        => $key,
        allow_head => 0,
    });
}

sub write_value {
    my $self = shift;
    my ($obj, $key, $value) = @_;

    my $r = Scalar::Util::reftype( $value ) || '';
    {
        last if $r eq '';
        last if $r eq 'HASH';
        last if $r eq 'ARRAY';

        DBM::Deep->_throw_error(
            "Storage of references of type '$r' is not supported."
        );
    }

    # Load the reference entry
    # Determine if the row was deleted under us
    # 

    my $sector = $self->load_sector( $obj->_base_offset, 'refs' )
        or die "Cannot load sector at '@{[$obj->_base_offset]}'\n";;

    my ($type, $class);
    if (
     $r eq 'ARRAY' || $r eq 'HASH' and ref $value ne 'DBM::Deep::Null'
    ) {
        my $tmpvar;
        if ( $r eq 'ARRAY' ) {
            $tmpvar = tied @$value;
        } elsif ( $r eq 'HASH' ) {
            $tmpvar = tied %$value;
        }

        if ( $tmpvar ) {
            my $is_dbm_deep = eval { local $SIG{'__DIE__'}; $tmpvar->isa( 'DBM::Deep' ); };

            unless ( $is_dbm_deep ) {
                DBM::Deep->_throw_error( "Cannot store something that is tied." );
            }

            unless ( $tmpvar->_engine->storage == $self->storage ) {
                DBM::Deep->_throw_error( "Cannot store values across DBM::Deep files. Please use export() instead." );
            }

            # Load $tmpvar's sector

            # First, verify if we're storing the same thing to this spot. If we
            # are, then this should be a no-op. -EJS, 2008-05-19
            
            # See whether or not we are storing ourselves to ourself.
            # Write the sector as data in this reference (keyed by $key)
            my $value_sector = $self->load_sector( $tmpvar->_base_offset, 'refs' );
            $sector->write_data({
                key     => $key,
#                key_md5 => $self->_apply_digest( $key ),
                value   => $value_sector,
            });
            $value_sector->increment_refcount;

            return 1;
        }

        $type = substr( $r, 0, 1 );
        $class = 'DBM::Deep::Sector::DBI::Reference';
    }
    else {
        if ( tied($value) ) {
            DBM::Deep->_throw_error( "Cannot store something that is tied." );
        }

        if ( ref $value eq 'DBM::Deep::Null' ) {
            DBM::Deep::_warnif(
             'uninitialized', 'Assignment of stale reference'
            );
            $value = undef;
        }

        $class = 'DBM::Deep::Sector::DBI::Scalar';
        $type  = 'S';
    }

    # Create this after loading the reference sector in case something bad
    # happens. This way, we won't allocate value sector(s) needlessly.
    my $value_sector = $class->new({
        engine => $self,
        data   => $value,
        type   => $type,
    });

    $sector->write_data({
        key     => $key,
#        key_md5 => $self->_apply_digest( $key ),
        value   => $value_sector,
    });

    $self->_descend( $value, $value_sector );

    return 1;
}

#sub begin_work {
#    my $self = shift;
#    die "Transactions are not supported by this engine"
#        unless $self->supports('transactions');
#
#    if ( $self->in_txn ) {
#        DBM::Deep->_throw_error( "Cannot begin_work within an active transaction" );
#    }
#
#    $self->storage->begin_work;
#
#    $self->in_txn( 1 );
#
#    return 1;
#} 
#
#sub rollback {
#    my $self = shift;
#    die "Transactions are not supported by this engine"
#        unless $self->supports('transactions');
#
#    if ( !$self->in_txn ) {
#        DBM::Deep->_throw_error( "Cannot rollback without an active transaction" );
#    }
#
#    $self->storage->rollback;
#
#    $self->in_txn( 0 );
#
#    return 1;
#} 
#
#sub commit {
#    my $self = shift;
#    die "Transactions are not supported by this engine"
#        unless $self->supports('transactions');
#
#    if ( !$self->in_txn ) {
#        DBM::Deep->_throw_error( "Cannot commit without an active transaction" );
#    }
#
#    $self->storage->commit;
#
#    $self->in_txn( 0 );
#
#    return 1;
#}
#
#sub in_txn {
#    my $self = shift;
#    $self->{in_txn} = shift if @_;
#    $self->{in_txn};
#}

sub supports {
    my $self = shift;
    my ($feature) = @_;

    return if $feature eq 'transactions';
    return 1 if $feature eq 'singletons';
    return;
}

sub db_version {
    return '1.0020'
}

sub clear {
    my $self = shift;
    my $obj = shift;

    my $sector = $self->load_sector( $obj->_base_offset, 'refs' )
        or return;

    $sector->clear;

    return;
}

1;
__END__