mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +02:00
0a96a2895d
The tests and documentation have been using the core storage layer but soon that will depend entirely on the C library, creating a bootstrap problem (i.e. the storage layer will be needed to build the C library). Create a simplified Posix storage layer to be used by documentation and the parts of the test code that build and execute the actual tests. The actual tests will still use the core storage driver so they can interact with any type of storage.
106 lines
3.0 KiB
Perl
106 lines
3.0 KiB
Perl
####################################################################################################################################
|
|
# Posix File Read
|
|
####################################################################################################################################
|
|
package pgBackRestTest::Common::StoragePosixRead;
|
|
use parent 'pgBackRest::Common::Io::Handle';
|
|
|
|
use strict;
|
|
use warnings FATAL => qw(all);
|
|
use Carp qw(confess);
|
|
use English '-no_match_vars';
|
|
|
|
use Fcntl qw(O_RDONLY);
|
|
|
|
use pgBackRest::Common::Exception;
|
|
use pgBackRest::Common::Log;
|
|
|
|
####################################################################################################################################
|
|
# CONSTRUCTOR
|
|
####################################################################################################################################
|
|
sub new
|
|
{
|
|
my $class = shift;
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
my
|
|
(
|
|
$strOperation,
|
|
$oDriver,
|
|
$strName,
|
|
$bIgnoreMissing,
|
|
) =
|
|
logDebugParam
|
|
(
|
|
__PACKAGE__ . '->new', \@_,
|
|
{name => 'oDriver', trace => true},
|
|
{name => 'strName', trace => true},
|
|
{name => 'bIgnoreMissing', optional => true, default => false, trace => true},
|
|
);
|
|
|
|
# Open the file
|
|
my $fhFile;
|
|
|
|
if (!sysopen($fhFile, $strName, O_RDONLY))
|
|
{
|
|
if (!($OS_ERROR{ENOENT} && $bIgnoreMissing))
|
|
{
|
|
logErrorResult($OS_ERROR{ENOENT} ? ERROR_FILE_MISSING : ERROR_FILE_OPEN, "unable to open '${strName}'", $OS_ERROR);
|
|
}
|
|
|
|
undef($fhFile);
|
|
}
|
|
|
|
# Create IO object if open succeeded
|
|
my $self;
|
|
|
|
if (defined($fhFile))
|
|
{
|
|
# Set file mode to binary
|
|
binmode($fhFile);
|
|
|
|
# Create the class hash
|
|
$self = $class->SUPER::new("'${strName}'", $fhFile);
|
|
bless $self, $class;
|
|
|
|
# Set variables
|
|
$self->{oDriver} = $oDriver;
|
|
$self->{strName} = $strName;
|
|
$self->{fhFile} = $fhFile;
|
|
}
|
|
|
|
# Return from function and log return values if any
|
|
return logDebugReturn
|
|
(
|
|
$strOperation,
|
|
{name => 'self', value => $self, trace => true}
|
|
);
|
|
}
|
|
|
|
####################################################################################################################################
|
|
# close - close the file
|
|
####################################################################################################################################
|
|
sub close
|
|
{
|
|
my $self = shift;
|
|
|
|
if (defined($self->handle()))
|
|
{
|
|
# Close the file
|
|
close($self->handle());
|
|
undef($self->{fhFile});
|
|
|
|
# Close parent
|
|
$self->SUPER::close();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
####################################################################################################################################
|
|
# Getters
|
|
####################################################################################################################################
|
|
sub handle {shift->{fhFile}}
|
|
sub name {shift->{strName}}
|
|
|
|
1;
|