mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-03-05 15:05:48 +02:00
Refactor storage layer to allow for new repository filesystems using drivers. (Reviewed by Cynthia Shang.) Refactor IO layer to allow for new compression formats, checksum types, and other capabilities using filters. (Reviewed by Cynthia Shang.)
105 lines
3.0 KiB
Perl
105 lines
3.0 KiB
Perl
####################################################################################################################################
|
|
# Posix File Read
|
|
####################################################################################################################################
|
|
package pgBackRest::Storage::Posix::FileRead;
|
|
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}}
|
|
|
|
1;
|