[30318] | 1 | ###############################################################################
|
---|
| 2 | #
|
---|
| 3 | # GDBM.pm -- utility functions for writing to gdbm databases
|
---|
| 4 | #
|
---|
| 5 | # A component of the Greenstone digital library software from the New Zealand
|
---|
| 6 | # Digital Library Project at the University of Waikato, New Zealand.
|
---|
| 7 | #
|
---|
| 8 | # Copyright (C) 1999-2015 New Zealand Digital Library Project
|
---|
| 9 | #
|
---|
| 10 | # This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | # the terms of the GNU General Public License as published by the Free Software
|
---|
| 12 | # Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | # version.
|
---|
| 14 | #
|
---|
| 15 | # This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
---|
| 17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
---|
| 18 | # more details.
|
---|
| 19 | #
|
---|
| 20 | # You should have received a copy of the GNU General Public License along with
|
---|
| 21 | # this program; if not, write to the Free Software Foundation, Inc., 675 Mass
|
---|
| 22 | # Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | #
|
---|
| 24 | ###############################################################################
|
---|
| 25 |
|
---|
| 26 | package DBDrivers::GDBM;
|
---|
| 27 |
|
---|
| 28 | # Pragma
|
---|
| 29 | use strict;
|
---|
| 30 |
|
---|
| 31 | # Libraries
|
---|
| 32 | use util;
|
---|
| 33 | use FileUtils;
|
---|
[30337] | 34 | use parent 'DBDrivers::70HyphenFormat';
|
---|
[30318] | 35 |
|
---|
| 36 |
|
---|
[30337] | 37 | ## @function constructor
|
---|
| 38 | #
|
---|
[30318] | 39 | sub new
|
---|
| 40 | {
|
---|
| 41 | my $class = shift(@_);
|
---|
[30337] | 42 | my $self = DBDrivers::70HyphenFormat->new(@_);
|
---|
| 43 | $self->{'default_file_extension'} = 'gdb';
|
---|
| 44 | # note: file separator agnostic
|
---|
| 45 | $self->{'executable_path'} = $ENV{'GSDLHOME'} . '/bin/' . $ENV{'GSDLOS'};
|
---|
| 46 | $self->{'read_executable'} = 'db2txt';
|
---|
| 47 | $self->{'keyread_executable'} = 'gdbmkeys';
|
---|
| 48 | $self->{'write_executable'} = 'txt2db';
|
---|
[30342] | 49 | $self->{'supports_set'} = 1;
|
---|
[30337] | 50 | bless($self, $class);
|
---|
| 51 | return $self;
|
---|
[30318] | 52 | }
|
---|
[30337] | 53 | ## new(void) => GDBM ##
|
---|
[30318] | 54 |
|
---|
[30337] | 55 |
|
---|
[30318] | 56 | # -----------------------------------------------------------------------------
|
---|
| 57 | # GDBM IMPLEMENTATION
|
---|
| 58 | # -----------------------------------------------------------------------------
|
---|
| 59 |
|
---|
[30337] | 60 | # Handled by BaseDBDriver
|
---|
| 61 | # sub get_infodb_file_path(string, string)
|
---|
[30318] | 62 |
|
---|
[30337] | 63 | # Handled by 70HyphenFormat
|
---|
| 64 | # sub close_infodb_write_handle(filehandle) => void
|
---|
| 65 | # sub delete_infodb_entry(filehandle, string) => void
|
---|
| 66 | # sub read_infodb_entry(string, string) => hashmap
|
---|
| 67 | # sub read_infodb_file(string, hashmap) => void
|
---|
| 68 | # sub read_infodb_keys(string, hashmap) => void
|
---|
| 69 | # sub read_infodb_rawentry(string, string) => string
|
---|
| 70 | # sub set_infodb_entry(string, string, hashmap) => integer
|
---|
| 71 | # sub write_infodb_entry(filehandle, string, hashmap) => void
|
---|
| 72 | # sub write_infodb_rawentry(filehandle, string, string) => void
|
---|
[30318] | 73 |
|
---|
| 74 |
|
---|
[30337] | 75 | ## @function open_infodb_write_handle(string, string*) => filehandle
|
---|
[30318] | 76 | #
|
---|
[30337] | 77 | # Handles legacy use of optional 'append' argument where '-append' is required
|
---|
[30318] | 78 | #
|
---|
[30337] | 79 | sub open_infodb_write_handle
|
---|
[30318] | 80 | {
|
---|
[30337] | 81 | my $self = shift(@_);
|
---|
[30318] | 82 | my $infodb_file_path = shift(@_);
|
---|
[30337] | 83 | my $opt_append = shift(@_);
|
---|
| 84 | my $infodb_file_handle;
|
---|
| 85 | if (defined $opt_append) {
|
---|
| 86 | if ($opt_append eq 'append') {
|
---|
| 87 | $opt_append = '-append';
|
---|
[30318] | 88 | }
|
---|
[30337] | 89 | $infodb_file_handle = $self->SUPER::open_infodb_write_handle($infodb_file_path, $opt_append);
|
---|
[30318] | 90 | }
|
---|
[30337] | 91 | else
|
---|
| 92 | {
|
---|
| 93 | $infodb_file_handle = $self->SUPER::open_infodb_write_handle($infodb_file_path);
|
---|
[30318] | 94 | }
|
---|
[30337] | 95 | return $infodb_file_handle;
|
---|
[30318] | 96 | }
|
---|
[30337] | 97 | ## open_infodb_write_handle(string, string*) => filehandle ##
|
---|
[30318] | 98 |
|
---|
| 99 | 1;
|
---|